Finite Difference Proof
Finite Difference Proof
C HAP. 9
over [a, b] with x(a) = and x(b) = . Form a partition of [a, b] using the points
a = t0 < t1 < < t N = b, where h = (b a)/N and t j = a + j h for j = 0, 1,
. . . , N . The central-difference formulas discussed in Chapter 6 are used to approximate
the derivatives
x(t j+1 ) x(t j1 )
x (t j ) =
+ O(h 2 )
(2)
2h
and
x(t j+1 ) 2x(t j ) + x(t j1 )
(3)
+ O(h 2 ).
x (t j ) =
h2
To start the derivation, we replace each term x(t j ) on the right side of (2) and (3)
with x j , and the resulting equations are substituted into (1) to obtain the relation
x j+1 2x j + x j1
x j+1 x j1
2
2
+
O(h
+
O(h
)
=
p(t
)
)
j
2h
h2
(4)
+ q(t j )x j + r (t j ).
Next, we drop the two terms O(h 2 ) in (4) and introduce the notation p j = p(t j ),
q j = q(t j ), and r j = r (t j ); this produces the difference equation
x j+1 2x j + x j1
x j+1 x j1
+ qjxj + rj,
= pj
2
2h
h
which is used to compute numerical approximations to the differential equation (1).
This is carried out by multiplying each side of (5) by h 2 and then collecting terms
involving x j1 , x j , and x j+1 and arranging them in a system of linear equations:
h
h
(6)
p j 1 x j1 + (2 + h 2 q j )x j +
p j 1 x j+1 = h 2r j ,
2
2
(5)
S EC . 9.9
537
2 + h 2 q1
h
2 p2 1
h
2 p1
2 + h 2 q2
h
2
pj 1
h
2 p2
2 + h2q j
h
2
p N 2 1
x1
x2
1
x
j
j
2 + h 2 q N 2 h2 p N 2 1 x N 2
h
2
p
1
2
+
h
q
x
N
1
N
1
N
1
2
O
h 2r1 + e0
h 2r2
2
,
h r j
=
h 2r N 2
h 2r N 1 + e N
where
e0 =
h
p1 + 1
2
and
eN =
h
p N 1 + 1 .
2
When computations with step size h are used, the numerical approximation to the
solution is a set of discrete points {(t j , x j )}; if the analytic solution x(t j ) is known, we
can compare x j and x(t j ).
Example 9.18.
2t
2
x (t)
x(t) + 1
2
1+t
1 + t2
with x(0) = 1.25 and x(4) = 0.95 over the interval [0, 4].
The functions p, q, and r are p(t) = 2t/(1 + t 2 ), q(t) = 2/(1 + t 2 ), and r (t) = 1,
respectively. The finite-difference method is used to construct numerical solutions {x j } using the system of equations (6). Sample values of the approximations {x j,1 }, {x j,2 }, {x j,3 },
and {x j,4 } corresponding to the step sizes h 1 = 0.2, h 2 = 0.1, h 3 = 0.05, and h 4 = 0.025
are given in Table 9.17. Figure 9.26 shows the graph of the polygonal path formed from
{(t j , x j,1 )} for the case h 1 = 0.2. There are 41 terms in the sequence generated with
h 2 = 0.1, and the sequence {x j,2 } only includes every other term from these computations;
they correspond to the 21 values of {t j } given in Table 9.17. Similarly, the sequences {x j,3 }
and {x j,4 } are a portion of the values generated with step sizes h 3 = 0.05 and h 4 = 0.025,
respectively, and they correspond to the 21 values of {t j } in Table 9.17.
Next we compare numerical solutions in Table 9.17 with the analytic solution: x(t) =
1.25 + 0.486089652t 2.25t 2 + 2t arctan(t) 12 ln(1 + t 2 ) + 12 t 2 ln(1 + t 2 ). The numerical
538
C HAP. 9
Table 9.17
tj
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
1.6
1.8
2.0
2.2
2.4
2.6
2.8
3.0
3.2
3.4
3.6
3.8
4.0
2t
2
x (t)
x(t) + 1
1 + t2
1 + t2
x j,1
h = 0.2
x j,2
h = 0.1
x j,3
h = 0.05
x j,4
h = 0.025
1.250000
1.314503
1.320607
1.272755
1.177399
1.042106
0.874878
0.683712
0.476372
0.260264
0.042399
0.170616
0.372557
0.557565
0.720114
0.854988
0.957250
1.022221
1.045457
1.022727
0.950000
1.250000
1.316646
1.325045
1.279533
1.186438
1.053226
0.887823
0.698181
0.492027
0.276749
0.059343
0.153592
0.355841
0.541546
0.705188
0.841551
0.945700
1.012958
1.038880
1.019238
0.950000
1.250000
1.317174
1.326141
1.281206
1.188670
1.055973
0.891023
0.701758
0.495900
0.280828
0.063537
0.149378
0.351702
0.537580
0.701492
0.838223
0.942839
1.010662
1.037250
1.018373
0.950000
1.250000
1.317306
1.326414
1.281623
1.189227
1.056658
0.891821
0.702650
0.496865
0.281846
0.064583
0.148327
0.350669
0.536590
0.700570
0.837393
0.942125
1.010090
1.036844
1.018158
0.950000
x(t j )
exact
1.250000
1.317350
1.326505
1.281762
1.189412
1.056886
0.892086
0.702947
0.497187
0.282184
0.064931
0.147977
0.350325
0.536261
0.700262
0.837116
0.941888
1.009899
1.036709
1.018086
0.950000
solutions can be shown to have error of order O(h 2 ). Hence reducing the step size by a
factor of 12 results in the error being reduced by about 14 . A careful scrutiny of Table 9.18
will reveal that this is happening. For instance, at t j = 1.0 the errors incurred with step
sizes h 1 , h 2 , h 3 , and h 4 are e j,1 = 0.014780, e j,2 = 0.003660, e j,3 = 0.000913, and e j,4 =
0.000228, respectively. Their successive ratios e j,2 /e j,1 = 0.003660/0.014780 = 0.2476,
e j,3 /e j,2 = 0.000913/0.003660 = 0.2495, and e j,4 /e j,3 = 0.000228/0.000913 = 0.2497
are approaching 14 .
Finally, we show how Richardsons improvement scheme can be used to extrapolate
the seemingly inaccurate sequences {x j,1 }, {x j,2 }, {x j,3 }, and {x j,4 } and obtain six digits
of precision. Eliminate the error terms O(h 2 ) and O((h/2)2 ) in the approximations {x j,1 }
and {x j,2 } by generating the extrapolated sequence {z j,1 } = {(4x j,2 x j,1 )/3}. Similarly,
the error terms O((h/2)2 ) and O((h/4)2 ) for {x j,2 } and {x j,3 } are eliminated by generating {z j,2 } = {(4x j,3 x j,2 )/3}. It has been shown that the second level of Richardsons
improvement scheme applies to the sequences {z j,1 } and {z j,2 }, so the third improvement
is {(16z j,2 z j,1 )/15}. Let us illustrate the situation by finding the extrapolated values that
S EC . 9.9
539
y
1.0
y = u(t)
0.5
t
0.0
0.5
1.0
2t
2
x (t)
x(t) + 1
1 + t2
1 + t2
(using h = 0.2).
Program 9.12 will call Program 9.11 to solve the tridiagonal system (6). Program 9.12 requires that the coefficient functions p(t), q(t), and r (t) (boundary value
problem (1)) be saved in M-files p.m, q.m, and r.m, respectively.
Program 9.11 (Tridiagonal Systems). To solve the tridiagonal system C X = B,
where C is a tridiagonal matrix.
function X=trisys(A,D,C,B)
540
C HAP. 9
Table 9.18
tj
x(t j ) x j,1
= e j,1
x(t j ) x j,2
= e j,2
x(t j ) x j,3
= e j,3
x(t j ) x j,4
= e j,4
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
1.6
1.8
2.0
2.2
2.4
2.6
2.8
3.0
3.2
3.4
3.6
3.8
4.0
h 1 = 0.2
0.000000
0.002847
0.005898
0.009007
0.012013
0.014780
0.017208
0.019235
0.020815
0.021920
0.022533
0.022639
0.022232
0.021304
0.019852
0.017872
0.015362
0.012322
0.008749
0.004641
0.000000
h 2 = 0.1
0.000000
0.000704
0.001460
0.002229
0.002974
0.003660
0.004263
0.004766
0.005160
0.005435
0.005588
0.005615
0.005516
0.005285
0.004926
0.004435
0.003812
0.003059
0.002171
0.001152
0.000000
h 3 = 0.05
0.000000
0.000176
0.000364
0.000556
0.000742
0.000913
0.001063
0.001189
0.001287
0.001356
0.001394
0.001401
0.001377
0.001319
0.001230
0.001107
0.000951
0.000763
0.000541
0.000287
0.000000
h 4 = 0.025
0.000000
0.000044
0.000091
0.000139
0.000185
0.000228
0.000265
0.000297
0.000322
0.000338
0.000348
0.000350
0.000344
0.000329
0.000308
0.000277
0.000237
0.000191
0.000135
0.000072
0.000000
S EC . 9.9
541
Table 9.19 Extrapolation of the Numerical Approximations {x j,1 }, {x j,2 }, {x j,3 } Obtained
with the Finite-Difference Method
tj
0.0
0.2
0.4
0.6
0.8
1.0
1.2
1.4
1.6
1.8
2.0
2.2
2.4
2.6
2.8
3.0
3.2
3.4
3.6
3.8
4.0
4x j,2 x j,1
4x j,3 x j,2
= z j,1
1.250000
1.317360
1.326524
1.281792
1.189451
1.056932
0.892138
0.703003
0.497246
0.282244
0.064991
0.147918
0.350268
0.536207
0.700213
0.837072
0.941850
1.009870
1.036688
1.018075
0.950000
= z j,2
1.250000
1.317351
1.326506
1.281764
1.189414
1.056889
0.892090
0.702951
0.497191
0.282188
0.064935
0.147973
0.350322
0.536258
0.700259
0.837113
0.941885
1.009898
1.036707
1.018085
0.950000
1.250000
1.317350
1.326504
1.281762
1.189412
1.056886
0.892086
0.702947
0.497187
0.282184
0.064931
0.147977
0.350325
0.536261
0.700263
0.837116
0.941888
1.009899
1.036708
1.018086
0.950000
x(t j )
Exact
solution
1.250000
1.317350
1.326505
1.281762
1.189412
1.056886
0.892086
0.702948
0.497187
0.282184
0.064931
0.147977
0.350325
0.536261
0.700262
0.837116
0.941888
1.009899
1.036708
1.018086
0.950000