Mathematical Methods for Physics and Engineering : A Comprehensive Guide

(lu) #1

27.6 DIFFERENTIAL EQUATIONS


x h y(exact)
0. 01 0.1 0.5 1.0 1.5 2 3
0 (1) (1) (1) (1) (1) (1) (1) (1)
0.5 0.605 0.590 0.500 0 − 0. 500 − 1 − 2 0.607
1.0 0.366 0.349 0.250 0 0. 250 1 4 0.368
1.5 0.221 0.206 0.125 0 − 0. 125 − 1 − 8 0.223
2.0 0.134 0.122 0.063 0 0. 063 1 16 0.135
2.5 0.081 0.072 0.032 0 − 0. 032 − 1 − 32 0.082
3.0 0.049 0.042 0.016 0 0. 016 1 64 0.050

Table 27.10 The solutionyof differential equation (27.61) using the Euler
forward difference method for various values ofh. The exact solution is also
shown.

27.6.1 Difference equations

Consider the differential equation


dy
dx

=−y, y(0) = 1, (27.61)

and the possibility of solving it numerically by approximatingdy/dxby a finite


difference along the lines indicated in section 27.5. We start with the forward


difference
(
dy
dx


)

xi


yi+1−yi
h

, (27.62)

where we use the notation of section 27.5 but withfreplaced byy.Inthis


particular case, it leads to the recurrence relation


yi+1=yi+h

(
dy
dx

)

i

=yi−hyi=(1−h)yi. (27.63)

Thus, sincey 0 =y(0) = 1 is given,y 1 =y(0 +h)=y(h) can be calculated, and


so on (this is theEulermethod). Table 27.10 shows the values ofy(x) obtained


if this is done using various values ofhand for selected values ofx. The exact


solution,y(x)=exp(−x), is also shown.


It is clear that to maintain anything like a reasonable accuracy only very small

steps,h, can be used. Indeed, ifhis taken to be too large, not only is the accuracy


bad but, as can be seen, forh>1 the calculated solution oscillates (when it


should be monotonic), and forh>2 it diverges. Equation (27.63) is of the form


yi+1=λyi, and a necessary condition for non-divergence is|λ|<1, i.e. 0<h<2,


though in no way does this ensure accuracy.


Part of this difficulty arises from the poor approximation (27.62); its right-

hand side is a closer approximation tody/dxevaluated atx=xi+h/2thanto


dy/dxatx=xi. This is the result of using a forward difference rather than the

Free download pdf