Numerical Methods
3.1 EULER’S METHOD
If an initial value problem
y0Df .x; y/; y.x
0/Dy0 (3.1.1)
can’t be solved analytically, it’s necessary to resort to numerical methods to obtain useful approximations to a solution of (3.1.1). We’ll consider such methods in this chapter.
We’re interested in computing approximate values of the solution of (3.1.1) at equally spaced points x0,x1, . . . ,xnDbin an intervalŒx0; b. Thus,
xiDx0Cih; iD0; 1; : : : ; n; where
hD b x0
n :
We’ll denote the approximate values of the solution at these points by y0,y1, . . . , yn; thus, yi is an approximation toy.xi/. We’ll call
eiDy.xi/ yi
theerror at theith step.Because of the initial conditiony.x0/Dy0, we’ll always havee0D0. However, in generalei ¤0ifi > 0.
We encounter two sources of error in applying a numerical method to solve an initial value problem:
The formulas defining the method are based on some sort of approximation. Errors due to the inaccuracy of the approximation are calledtruncation errors.
Computers do arithmetic with a fixed number of digits, and therefore make errors in evaluating the formulas defining the numerical methods. Errors due to the computer’s inability to do exact arithmetic are calledroundoff errors.
Since a careful analysis of roundoff error is beyond the scope of this book, we’ll consider only trunca- tion errors.
Euler’s Method
The simplest numerical method for solving (3.1.1) isEuler’s method. This method is so crude that it is seldom used in practice; however, its simplicity makes it useful for illustrative purposes.
Euler’s method is based on the assumption that the tangent line to the integral curve of (3.1.1) at .xi; y.xi//approximates the integral curve over the intervalŒxi; xiC1. Since the slope of the integral curve of (3.1.1) at.xi; y.xi//isy0.xi/D f .xi; y.xi//, the equation of the tangent line to the integral curve at.xi; y.xi//is
yDy.xi/Cf .xi; y.xi//.x xi/: (3.1.2) SettingxDxiC1DxiChin (3.1.2) yields
yiC1Dy.xi/Chf .xi; y.xi// (3.1.3) as an approximation toy.xiC1/. Sincey.x0/Dy0is known, we can use (3.1.3) withiD0to compute
y1Dy0Chf .x0; y0/: However, settingi D1in (3.1.3) yields
Section 3.1Euler’s Method 97 which isn’t useful, since wedon’t knowy.x1/. Therefore we replacey.x1/by its approximate valuey1 and redefine
y2Dy1Chf .x1; y1/: Having computedy2, we can compute
y3Dy2Chf .x2; y2/:
In general, Euler’s method starts with the known valuey.x0/Dy0and computesy1,y2, . . . ,ynsucces- sively by with the formula
yiC1DyiChf .xi; yi/; 0in 1: (3.1.4) The next example illustrates the computational procedure indicated in Euler’s method.
Example 3.1.1 Use Euler’s method withhD0:1to find approximate values for the solution of the initial value problem y0C2yDx3e 2x; y.0/D1 (3.1.5) atxD0:1; 0:2; 0:3. Solution We rewrite (3.1.5) as y0D 2yCx3e 2x; y.0/ D1; which is of the form (3.1.1), with
f .x; y/D 2yCx3e 2x; x0D0; andy0D1: Euler’s method yields
y1 D y0Chf .x0; y0/ D 1C.:1/f .0; 1/D1C.:1/. 2/D:8; y2 D y1Chf .x1; y1/ D :8C.:1/f .:1; :8/D:8C.:1/ 2.:8/C.:1/3e :2 D:640081873; y3 D y2Chf .x2; y2/ D :640081873C.:1/ 2.:640081873/C.:2/3e :4 D:512601754:
We’ve written the details of these computations to ensure that you understand the procedure. However, in the rest of the examples as well as the exercises in this chapter, we’ll assume that you can use a programmable calculator or a computer to carry out the necessary computations.
Examples Illustrating The Error in Euler’s Method
Example 3.1.2 Use Euler’s method with step sizesh D0:1,h D0:05, andh D0:025to find approxi- mate values of the solution of the initial value problem
y0C2yDx3e 2x; y.0/
D1
atxD0,0:1,0:2,0:3, . . . ,1:0. Compare these approximate values with the values of the exact solution y D e
2x 4 .x
4
C4/; (3.1.6)
Solution Table3.1.1shows the values of the exact solution (3.1.6) at the specified points, and the ap- proximate values of the solution at these points obtained by Euler’s method with step sizes h D 0:1, hD 0:05, andhD0:025. In examining this table, keep in mind that the approximate values in the col- umn corresponding tohD:05are actually the results of 20 steps with Euler’s method. We haven’t listed the estimates of the solution obtained forxD0:05,0:15, . . . , since there’s nothing to compare them with in the column corresponding tohD0:1. Similarly, the approximate values in the column corresponding tohD0:025are actually the results of 40 steps with Euler’s method.
Table 3.1.1. Numerical solution ofy0C2yDx3e 2x; y.0/
D1, by Euler’s method. x hD0:1 hD0:05 hD0:025 Exact 0.0 1.000000000 1.000000000 1.000000000 1.000000000 0.1 0.800000000 0.810005655 0.814518349 0.818751221 0.2 0.640081873 0.656266437 0.663635953 0.670588174 0.3 0.512601754 0.532290981 0.541339495 0.549922980 0.4 0.411563195 0.432887056 0.442774766 0.452204669 0.5 0.332126261 0.353785015 0.363915597 0.373627557 0.6 0.270299502 0.291404256 0.301359885 0.310952904 0.7 0.222745397 0.242707257 0.252202935 0.261398947 0.8 0.186654593 0.205105754 0.213956311 0.222570721 0.9 0.159660776 0.176396883 0.184492463 0.192412038 1.0 0.139778910 0.154715925 0.162003293 0.169169104
You can see from Table3.1.1that decreasing the step size improves the accuracy of Euler’s method. For example, yexact.1/ yapprox.1/ 8 < : :0293withhD0:1; :0144withhD0:05; :0071withhD0:025:
Based on this scanty evidence, you might guess that the error in approximating the exact solution at afixed value ofxby Euler’s method is roughly halved when the step size is halved. You can find more evidence to support this conjecture by examining Table3.1.2, which lists the approximate values ofyexact yapprox at
xD0:1,0:2, . . . ,1:0.
Table 3.1.2. Errors in approximate solutions ofy0C2yD x3e 2x; y.0/
D1, obtained by Euler’s method. x hD0:1 hD0:05 hD0:025 0.1 0.0187 0.0087 0.0042 0.2 0.0305 0.0143 0.0069 0.3 0.0373 0.0176 0.0085 0.4 0.0406 0.0193 0.0094 0.5 0.0415 0.0198 0.0097 0.6 0.0406 0.0195 0.0095 0.7 0.0386 0.0186 0.0091 0.8 0.0359 0.0174 0.0086 0.9 0.0327 0.0160 0.0079 1.0 0.0293 0.0144 0.0071
Example 3.1.3 Tables3.1.3and3.1.4show analogous results for the nonlinear initial value problem
Section 3.1Euler’s Method 99 except in this case we can’t solve (3.1.7) exactly. The results in the “Exact” column were obtained by using a more accurate numerical method known as theRunge-Kuttamethod with a small step size. They are exact to eight decimal places.
Since we think it’s important in evaluating the accuracy of the numerical methods that we’ll be studying in this chapter, we often include a column listing values of the exact solution of the initial value problem, even if the directions in the example or exercise don’t specifically call for it. If quotation marks are included in the heading, the values were obtained by applying the Runge-Kutta method in a way that’s explained in Section 3.3. If quotation marks are not included, the values were obtained from a known formula for the solution. In either case, the values are exact to eight places to the right of the decimal point.
Table 3.1.3. Numerical solution ofy0 D 2y2CxyCx2; y.0/D1, by Euler’s method.
x hD0:1 hD0:05 hD0:025 “Exact” 0.0 1.000000000 1.000000000 1.000000000 1.000000000 0.1 0.800000000 0.821375000 0.829977007 0.837584494 0.2 0.681000000 0.707795377 0.719226253 0.729641890 0.3 0.605867800 0.633776590 0.646115227 0.657580377 0.4 0.559628676 0.587454526 0.600045701 0.611901791 0.5 0.535376972 0.562906169 0.575556391 0.587575491 0.6 0.529820120 0.557143535 0.569824171 0.581942225 0.7 0.541467455 0.568716935 0.581435423 0.593629526 0.8 0.569732776 0.596951988 0.609684903 0.621907458 0.9 0.614392311 0.641457729 0.654110862 0.666250842 1.0 0.675192037 0.701764495 0.714151626 0.726015790
Table 3.1.4. Errors in approximate solutions ofy0D 2y2CxyCx2; y.0/D1, obtained by Euler’s method. x hD0:1 hD0:05 hD0:025 0.1 0.0376 0.0162 0.0076 0.2 0.0486 0.0218 0.0104 0.3 0.0517 0.0238 0.0115 0.4 0.0523 0.0244 0.0119 0.5 0.0522 0.0247 0.0121 0.6 0.0521 0.0248 0.0121 0.7 0.0522 0.0249 0.0122 0.8 0.0522 0.0250 0.0122 0.9 0.0519 0.0248 0.0121 1.0 0.0508 0.0243 0.0119
Truncation Error in Euler’s Method
Consistent with the results indicated in Tables 3.1.1–3.1.4, we’ll now show that under reasonable as- sumptions onf there’s a constantKsuch that the error in approximating the solution of the initial value problem
y0Df .x; y/; y.x
0/Dy0;
at a given pointb > x0by Euler’s method with step sizehD.b x0/=nsatisfies the inequality
whereKis a constant independent ofn.
There are two sources of error (not counting roundoff) in Euler’s method:
1. The error committed in approximating the integral curve by the tangent line (3.1.2) over the interval Œxi; xiC1.
2. The error committed in replacingy.xi/byyi in (3.1.2) and using (3.1.4) rather than (3.1.2) to computeyiC1.
Euler’s method assumes thatyiC1defined in (3.1.2) is an approximation toy.xiC1/. We call the error in this approximation thelocal truncation error at theith step, and denote it byTi; thus,
TiDy.xiC1/ y.xi/ hf .xi; y.xi//: (3.1.8) We’ll now useTaylor’s theoremto estimateTi, assuming for simplicity thatf,fx, andfyare continuous and bounded for all.x; y/. Theny00exists and is bounded onŒx0; b. To see this, we differentiate
y0.x/Df .x; y.x// to obtain
y00.x/ D f
x.x; y.x//Cfy.x; y.x//y0.x/
D fx.x; y.x//Cfy.x; y.x//f .x; y.x//: Since we assumed thatf,fx andfyare bounded, there’s a constantMsuch that
jfx.x; y.x//Cfy.x; y.x//f .x; y.x//j M; x0< x < b; which implies that
jy00.x/j M; x0< x < b: (3.1.9) SincexiC1DxiCh, Taylor’s theorem implies that
y.xiC1/Dy.xi/Chy0.xi/C h2
2 y 00.xQ
i/;
wherexQiis some number betweenxiandxiC1. Sincey0.xi/Df .xi; y.xi//this can be written as y.xiC1/Dy.xi/Chf .xi; y.xi//C
h2 2 y
00.xQ
i/; or, equivalently,
y.xiC1/ y.xi/ hf .xi; y.xi//D h2
2 y 00.xQ
i/: Comparing this with (3.1.8) shows that
Ti D h2
2 y 00.xQ
i/: Recalling (3.1.9), we can establish the bound
jTij M h2
2 ; 1i n: (3.1.10)
Although it may be difficult to determine the constantM, what is important is that there’s anM such that (3.1.10) holds. We say that the local truncation error of Euler’s method isof orderh2, which we write as O.h2/.
Section 3.1Euler’s Method 101 Note that the magnitude of the local truncation error in Euler’s method is determined by the second derivativey00 of the solution of the initial value problem. Therefore the local truncation error will be
larger wherejy00jis large, or smaller wherejy00jis small.
Since the local truncation error for Euler’s method isO.h2/, it’s reasonable to expect that halvingh reduces the local truncation error by a factor of 4. This is true, but halving the step size also requires twice as many steps to approximate the solution at a given point. To analyze the overall effect of truncation error in Euler’s method, it’s useful to derive an equation relating the errors
eiC1Dy.xiC1/ yiC1 and eiDy.xi/ yi: To this end, recall that
y.xiC1/Dy.xi/Chf .xi; y.xi//CTi (3.1.11) and
yiC1DyiChf .xi; yi/: (3.1.12) Subtracting (3.1.12) from (3.1.11) yields
eiC1DeiCh Œf .xi; y.xi// f .xi; yi/CTi: (3.1.13) The last term on the right is the local truncation error at theith step. The other terms reflect the way errors made atprevious stepsaffecteiC1. SincejTij M h2=2, we see from (3.1.13) that
jeiC1j jeij Chjf .xi; y.xi// f .xi; yi/j C M h2
2 : (3.1.14)
Since we assumed thatfyis continuous and bounded, the mean value theorem implies that f .xi; y.xi// f .xi; yi/Dfy.xi; yi/.y.xi/ yi/Dfy.xi; yi/ei; wherey
i is betweenyiandy.xi/. Therefore
jf .xi; y.xi// f .xi; yi/j Rjeij for some constantR. From this and (3.1.14),
jeiC1j .1CRh/jeij C M h2
2 ; 0in 1: (3.1.15)
For convenience, letC D1CRh. Sincee0Dy.x0/ y0D0, applying (3.1.15) repeatedly yields
je1j M h2 2 je2j Cje1j C M h2 2 .1CC / M h2 2 je3j Cje2j C M h2 2 .1CC CC 2 /M h 2 2 :: : jenj Cjen 1j C M h2 2 .1CCC CC n 1 /M h 2 2 : (3.1.16)
Recalling the formula for the sum of a geometric series, we see that
1CC C CCn 1 D 1 C
n
1 C D
.1CRh/n 1 Rh
(sinceC D1CRh). From this and (3.1.16), jy.b/ ynj D jenj .1CRh/n 1 R M h 2 : (3.1.17)
Since Taylor’s theorem implies that
1CRh < eRh (verify),
.1CRh/n< enRhDeR.b x0/ .sincenh
Db x0/: This and (3.1.17) imply that
jy.b/ ynj Kh; (3.1.18)
with
KDMe
R.b x0/ 1
2R :
Because of (3.1.18) we say that theglobal truncation error of Euler’s method is of order h, which we write asO.h/.
Semilinear Equations and Variation of Parameters
An equation that can be written in the form
y0Cp.x/yDh.x; y/ (3.1.19)
withp6 0is said to besemilinear. (Of course, (3.1.19) is linear ifhis independent ofy.) One way to apply Euler’s method to an initial value problem
y0Cp.x/y Dh.x; y/; y.x0/Dy0 (3.1.20) for (3.1.19) is to think of it as
y0Df .x; y/; y.x
0/Dy0; where
f .x; y/D p.x/yCh.x; y/:
However, we can also start by applying variation of parameters to (3.1.20), as in Sections 2.1 and 2.4; thus, we write the solution of (3.1.20) asyDuy1, wherey1is a nontrivial solution of the complementary equationy0Cp.x/y D 0. Theny D uy
1is a solution of (3.1.20) if and only ifuis a solution of the initial value problem
u0 Dh.x; uy1.x//=y1.x/; u.x0/Dy.x0/=y1.x0/: (3.1.21) We can apply Euler’s method to obtain approximate valuesu0,u1, . . . ,unof this initial value problem, and then take
yiDuiy1.xi/
as approximate values of the solution of (3.1.20). We’ll call this procedure theEuler semilinear method. The next two examples show that the Euler and Euler semilinear methods may yield drastically different results.
Example 3.1.4 In Example2.1.7we had to leave the solution of the initial value problem
y0 2xy D1; y.0/D3 (3.1.22) in the form yDex2 3C Z x 0 e t2dt (3.1.23)
Section 3.1Euler’s Method 103 because it was impossible to evaluate this integral exactly in terms of elementary functions. Use step sizesh D0:2,h D 0:1, andh D 0:05to find approximate values of the solution of (3.1.22) atx D 0, 0:2,0:4,0:6, . . . ,2:0by(a)Euler’s method;(b)the Euler semilinear method.
SOLUTION(a) Rewriting (3.1.22) as
y0D1C2xy; y.0/D3 (3.1.24)
and applying Euler’s method withf .x; y/D1C2xyyields the results shown in Table3.1.5. Because of the large differences between the estimates obtained for the three values ofh, it would be clear that these results are useless even if the “exact” values were not included in the table.
Table 3.1.5. Numerical solution ofy0 2xyD1; y.0/D3, with Euler’s method.
x hD0:2 hD0:1 hD0:05 “Exact” 0.0 3.000000000 3.000000000 3.000000000 3.000000000 0.2 3.200000000 3.262000000 3.294348537 3.327851973 0.4 3.656000000 3.802028800 3.881421103 3.966059348 0.6 4.440960000 4.726810214 4.888870783 5.067039535 0.8 5.706790400 6.249191282 6.570796235 6.936700945 1.0 7.732963328 8.771893026 9.419105620 10.184923955 1.2 11.026148659 13.064051391 14.405772067 16.067111677 1.4 16.518700016 20.637273893 23.522935872 27.289392347 1.6 25.969172024 34.570423758 41.033441257 50.000377775 1.8 42.789442120 61.382165543 76.491018246 98.982969504 2.0 73.797840446 115.440048291 152.363866569 211.954462214
It’s easy to see why Euler’s method yields such poor results. Recall that the constantM in (3.1.10) – which plays an important role in determining the local truncation error in Euler’s method – must be an upper bound for the values of the second derivativey00of the solution of the initial value problem (3.1.22)
on.0; 2/. The problem is thaty00assumes very large values on this interval. To see this, we differentiate
(3.1.24) to obtain
y00.x/D2y.x/C2xy0.x/D2y.x/C2x.1C2xy.x//D2.1C2x2
/y.x/C2x;
where the second equality follows again from (3.1.24). Since (3.1.23) implies thaty.x/ > 3ex2ifx > 0, y00.x/ > 6.1C2x2/ex2
C2x; x > 0: For example, lettingxD2shows thaty00.2/ > 2952.
SOLUTION(b) Sincey1Dex
2
is a solution of the complementary equationy0 2xyD0, we can apply
the Euler semilinear method to (3.1.22), with
yDuex2 and u0De x2
; u.0/D3:
The results listed in Table3.1.6are clearly better than those obtained by Euler’s method.
x hD0:2 hD0:1 hD0:05 “Exact”