0% found this document useful (0 votes)
7 views

Finite Difference Method

Finite Difference Method

Uploaded by

sasafafs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Finite Difference Method

Finite Difference Method

Uploaded by

sasafafs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

660 C HAP T E R 11 • Boundary-Value Problems for Ordinary Differential Equations

6. The Van der Pol equation,

y" - f..t(y2 - l)y' +y = 0, f..t > 0,

governs the flow of current in a vacuum tube with three internal elements. Let f..t = ~, yeO) =
0, and y(2) = 1. Approximate the solution yet) for t = 0.2i, where I < i ::5 9.

11.3 Finite-Difference Methods for Linear Problems


The linear and nonlinear Shooting methods for boundary-value problems can present prob-
lems of instability. The methods in this section have better stability characteristics, but they
generally require more computation to obtain a specified accuracy.
Methods involving finite differences for solving boundary-value problems replace
each of the derivatives in the differential equation with an appropriate difference-quotient
approximation of the type considered in Section 4.1. The particular difference quotient and
step size h are chosen to maintain a specified order of truncation error. However, h cannot
be chosen too small because of the instability of the derivative approximations.
The finite difference method for the linear second-order boundary-value problem,

y" = p(x)y' + q(x)y + rex), a <X < b, yea) = a, y(b) = {3, (11.14)

requires that difference-quotient approximations be used to approximate both y' and y".
First, we select an integer N > 0 and divide the interval [a, b] into (N + 1) equal subin-
tervals whose endpoints are the mesh points Xi = a + ih, for i = 0, 1, ... , N + 1, where
h = (b - a)j(N + 1). Choosing the step size h in this manner facilitates the application
of a matrix algorithm from Chapter 6, which solves a linear system involving an N x N
matrix.
At the interior mesh points, Xi, for i = 1, 2, ... , N, the differential equation to be
approximated is

y" (Xi) = P (Xi) y' (Xi) + q (Xi) Y (Xi) + r (Xi)· (11.15)

Expanding y in a third Taylor polynomial about Xi evaluated at Xi+1 and Xi-I, we have,
assuming that y E C 4 [Xi_l, xi+d,

for some ~t in (Xi, Xi+I), and


11.3 Finite-Difference Methodsfor Unear Problems 661

for some ~i- in (Xi -I, Xi). If these equations are added, we have

and solving for y" (Xi) gives

The Intetmediate Value Theorem can be used to simplify this to

(11.16)

for some ~i in (Xi-I, Xi+l)' This is called the centered-difference formula for y"(x;).
A centered-difference formula for y' (Xi) is obtained in a similar manner (the details
were considered in Section 4.1), resulting in

(11.17)

for some '7i in (Xi-I, Xi+l)'


The use of these centered-difference fOllnulas in Eq. (11.15) results in the equation

y(xi+d - Y(Xi-l)
2h
+ q (Xi )Y (Xi )

A Finite-Difference method with truncation error of order O(h2) results by using this
equation together with the boundary conditions yea) = a and y(b) = fJ to define

Wo = a,

and

-Wi+1 + 2Wi - Wi-I


+ q(Xi)Wi = -r(xi),
+ P(Xi) (11.18)
h2

for each i = 1, 2, ... , N.


In the fOlln we will consider, Eq. (11.18) is rewritten as

and the resulting system of equations is expressed in the tridiagonal N x N matrix fOlIn

Aw = b, where (11.19)
662 C HAP T E R 11 • Boundary-Value Problems for Ordinary Differential Equations

h
2 + h 2q(XI) -1 + 2 P(XI) 0:::·························· 0
• •
h •

-1 - 2 P (X?! 2+ h 2q(X2) •


• • • •

A= o. •

• •

• • •


o ,
• •


• • •
• •
• .. h



• •


. . 2 P (XN I) -I +
• •
· • . . '. h'· . . . ,
0························ ::·0 -I - 2 P (XN) . 2+h-q(XN)

h
I+ P(XI) Wo
2

w= •


, and b=

The following theorem gives conditions under which the tridiagonal linear system
(11.19) has a unique solution. Its proof is a consequence of Theorem 6.29 and is considered
in Exercise 9.

Theorem 11.3 Suppose that p, q, and r are continuous on [a, b]. If q(x) > 0 on [a, b], then the tridi-
agonal linear system (1l.19) has a unique solution provided that h < 2jL, where L
maxa<x:cb Ip(x)l· •


It should be noted that the hypotheses of Theorem 11.3 guarantee a unique solution to
the boundary-value problem (11.14), but they do not guarantee that y E C 4 [a, b J. We need
to establish that l4) is continuous on [a, b J to ensure that the truncation error has order
O(h2).
Algorithm 11.3 implements the Linear Finite-Difference method.

Linear Finite-Difference
To approximate the solution of the boundary-value problem

y" = p(x)y' + q(x)y + rex), a < x <b, yea) = a, y(b) = /3 :


INPUT endpoints a, b; boundary conditions a, /3; integer N > 2.

OUTPUT approximations Wi to y (Xi) for each i = 0, 1, ... , N + 1.

Step 1 Set h = (b - a)j(N + I);


x = a + h;
al = 2 + h2q(x);
b l = -1 + (hj2)p(x);
d l = -h 2 r(x) + (1 + (hj2)p(x»a.
11.3 Finite-Difference Methods for Linear Problems 663

Step 2 For i = 2, ... ,N - 1


set x = a + ih;
ai = 2 + h2q(X);
b i = -1 + (h/2)p(x);
Ci = -1 - (h/2)p(x);
d i = -h 2 r(x).

Step 3 Set x = b - h;
aN = 2 + h2q(x);
CN = -1 - (h/2)p(x);
d N = -h 2 r(x) + (1 - (h/2)p(x»f3.

Step 4 Set 11 = a1; (Steps 4-8 solve a tridiagonal linear system using Algorithm 6.7.)
UI = bl/a];
;:1 = d l / I].

Step 5 For i = 2, ... , N - 1 set Ii = a, - CiUi-l;


Ui = bi! Ii;
Zi = (di - CiZi-])/ Ii.

Step 6 Set IN = aN - CNUN-I;


ZN = (dN - CNZN-I)/ IN.
Step 7 Set Wo = 0';
WN+I = f3.
WN = ZN·

StepB For i = N - 1, .... 1 set Wi = Zi - UiWi+].


Step 9 For i = 0, ... , N + 1 set x = a + i h;
OUTPUT (x, Wi)'

Step 10 STOP. (The procedure is complete.) •


EXAMPLE 1 Algorithm 11.3 will he used to approximate the solution to the linear boundary- value prob-
lem
" 2 1 2 sin (In x)
y = --y + -2y + --::--,
2
1 < x < 2, y(1) = 1, y(2) = 2.
X x x
which was also approximated by the Shooting method in Example 2 of Section 11.1. For
this example, we will use N = 9, so h = 0.1, and we have the same spacing as in Example
2 of Section 11.1. The complete results are listed in Table 11.3 on page 664.
These results are considerably less accurate than those obtained in Example 2 of Sec-
tion 11.1. This is because the method used in that example involved a Runge- Kutta tech-
nique with local truncation error of order O(h 4 ), whereas the difference method used here
has local truncation error of order O(h2). •

To obtain a difference method with greater accuracy, we can proceed in a number


of ways. Using fifth-order Taylor series for approximating il (Xi) and i (Xi) results in a
truncation error term involving h4. However, this process requires using multiples not only
664 C HAP T E R 11 • Boundary-Value Problems for Ordinary Differential Equations

ntble 113 Xj Wj Y(Xj) !Wj - Y(Xj)!

1.0 1.00000000 1.00000000


1.1 1.09260052 1.09262930 2.88 x 10- 5
1.2 1.18704313 1.18708484 4.17 x 10- 5
1.3 1.28333687 1.28338236 4.55 x 10-5
1.4 1.38140205 1.38144595 4.39 x 10- 5
1.5 1.48112026 1.48115942 3.92 x 10- 5
1.6 1.58235990 1.58239246 3.26 x 10-5
1.7 1.68498902 1.68501396 2.49 x 10- 5
1.8 1.78888175 1.78889853 1.68 x 10-5
1.9 1.89392110 1.89392951 8.41 x 10-6
2.0 2.00000000 2.00000000

of Y(Xi+l) and Y(Xi-l), but also of Y(Xi+2) and Y(Xi-2) in the approximation forlIlulas for
y" (Xi) and y' (Xi)' This leads to difficulty at i = a and i = N. Moreover, the resulting
system of equations analogous to (11.1 9) is not in tridiagonal fonn, and the solution to the
system requires many more calculations.
Instead of attempting to obtain a difference method with a higher-order truncation
error in this manner, it is generally more satisfactory to consider a reduction in step size.
In addition, Richardson's extrapolation technique can be used effectively for this method
since the error tenn is expressed in even powers of h with coefficients independent of h,
provided Y is sufficiently differentiable (see, for example, [Keller, H, p. 81]).

EXAMPLE 2 Applying Richardson's extrapolation to approximate the solution to the boundary-value


problem

2 I 2 sin(lnx)
y" = - - y
X
+ x2
- y + ---;:---'-
x2'
1 .::: X .::: 2, y(l) = 1, y(2) = 2,

with h = O. I, 0.05, and 0.025, gives the results listed in Table 1 1.4. The first extrapolation

IS

ntble 11A
Xj wj(h = 0.1) wj(h = 0.05) Wj (h = 0.025) ExtJj Ext2j Ext3j

1.0 1.00000000 1.00000000 1.00000000 1.00000000 1.00000000 1. OOOOOOOO


1.1 1.09260052 1.09262207 1.09262749 1.09262925 1.09262930 1.09262930
1,2 1.18704313 1.18707436 1.18708222 1.l8708477 1.18708484 1.18708484
1.3 1.28333687 1.28337094 1.28337950 1.28338230 1.28338236 1.28338236
1.4 1.38140205 1.38143493 1.38144319 1.38144589 1.38144595 1.38144595
1.5 1.48112026 1.48114959 1.48115696 1.48115937 1.48115941 1.48115942
1.6 1.58235990 1.58238429 1.58239042 1.58239242 1.58239246 1.58239246
1.7 1.68498902 1.68500770 1.68501240 1.68501393 1.68501396 1.68501396
1.8 1.78888175 1.78889432 1.78889748 1.78889852 1.78889853 1.78889853
1.9 1.89392110 1.89392740 1.89392898 1.89392950 1.89392951 1.89392951
2.0 2.00000000 2.00000000 2.00000000 2. OOOOOOOO 2.00000000 2. OOOOOOOO
11.3 FInite-Difference Methods for LInear Problems 665

the second extrapolation is

4Wi (h = 0.025) - Wi (h = 0.05)


Ext2i = 3 ;

and the final extrapolation is

16Ext2i - Extli
Ext3' =
I
---=---::...
15

All the results of EXt3i are correct to the decimal places listed. In fact, if sufficient dig-
its had been used, this approximation would agree with the exact solution with maximum
error of 6.3 x 10- 11 at the mesh points, an impressive improvement. -

E X ERe I S E SET 11.3


1. The boundary-value problem

y" = 4(y - x), 0 < x :5 I, yeO) = 0, y(l) =2


has the solution y(x) = e 2(e 4 -l)-l(e 2x - e- 2x ) + x. Use the Linear Finite-Difference Algo-
rithm to approximate the solution, and compare the results to the actual solution.
a. With h = ~; b. With h = !.
c. Use extrapolation to approximate y(l/2).
2. The boundary-value problem

y"=y'+2y+cosx, O<x<~, y(O) =-0.3, y(~)=-O.l

has the solution y(x) = - l~ (sin x + 3 cos x). Use the Linear Finite-Difference Algorithm to
approximate the solution, and compare the results to the actual solution.
a. With h = ~; b. With h = ~.
c. Use extrapolation to approximate y(rr /4).
3. Use the Linear Finite-Difference Algorithm to approximate the solution to the following
boundary-value problems.
a. y" = -3y' + 2y + 2x + 3, 0 <x < I, yeO) = 2, y(l) = I; use h = 0.1.
b. y" = -:y' +!ry - ~ lnx, 1:5 x <2, y(l) = -i, y(2) = In2; use h = 0.05.
c. y" = -(x + I)y' + 2y + (l - x 2 )e- x , 0:5 x < I, yeO) = -I, y(l) = 0; use h = 0.1.
d. y" = f + .!rY + ~x - I, 1:5 x :5 2, y(l) = y(2) = 0; use h = 0.1.
4. Although q (x) < 0 in the following boundary-value problems, unique solutions exist and are
given. Use the Linear Finite-Difference Algorithm to approximate the solutions, and compare
the results to the actual solutions.
a. y" + Y = 0, 0 < x < ~,y(O) = I, y(~) = 1; use h = :0; actual solution y(x) =
cos x + (.J2 - 1) sinx.
666 C HAP T E R 11 • Boundary-Value Problemsfor Ordinary Differential Equations

b. y" + 4y = cosx, 0 < x :'S: ~, yeO) == 0, y(~) = 0; use h = ;; actual solution


y(x) = -j cos2x - f sin2x + j cosx.
c. y" = - 4 x 2 y + 2lnx
x y' - l.. x2 ' 1 -< x <- 2 , y(l) = !2' y(2) = In 2', use h = 0.05', actual
solution y(x) = x4 - x22 + Inx - 32 ,
,
d. y" = 2y' - y + xe X - x, 0 < x < 2, yeO) = 0, y(2) = -4; use h = 0.2; actual
solution y(x) = ~x3ex - ;xe x + 2e x - x - 2.
S. Use the Linear Finite-Difference Algorithm to approximate the solution y = e-lO)C to the
boundary-value problem

y" = lOOy, 0 <x < I, yeO) = 1, y(l) = e- IO

Use h = 0.1 and 0.05. Can you explain the consequences?


6. Repeat Exercise 3(a) and (b) using the extrapolation discussed in Example 2.
7. The lead example of this chapter concerned the deflection of a beam with supported ends
subject to uniform loading. The boundary-value problem governing this physical situation is

d1w S qx
dx 2 = EI W + 2EI (x -1), 0 < x < 1,

with boundary conditions w(O) = 0 and w(l) = O.


Suppose the beam is a WlO-type steel I-beam with the following characteristics: length
I = 120 in., intensity of uniform load q = 100 lb/ft, modulus of elasticity E = 3.0 X 107
lb/in. z, stress at ends S = 1000 lb, and central moment of inertia 1= 625 in.4.
a. Approximate the deflection w (x) of the beam every 6 in.
b. The actual relationship is given by

w(x) = Clea;: + cze- ax + b(x -l)x + c,


where CI = 7.7042537 X 104, Cz = 7.9207462 x 104, a = 2.3094010 x 10- 4, b
-4.1666666 X 10- 3 , and C = -1.5625 X 105 . Is the maximum error on the interval
WI·thin 02'
. Ill ..?
c. State law requires that maxo<x<[ w(x) < 1/300. Does this beam meet state code?
8. The deflection of a uniformly loaded, long rectangular plate under an axial tension force is
governed by a second·order differential equation. Let S represent the axial force and q the
intensity of the uniform load. The deflection W along the elemental length is given by

S -ql q
W"(x) - D W(x) = 2D x + 2D x2 , 0 <x < I, W(O) = W(l) = 0,

where I is the length of the plate and D is the flexual rigidity of the plate. Let q = 200
Ib/in. z, S = 100 Ib/in., D = 8.8 X 107 lb/in., and I = 50 in. Approximate the deflection at
I-in. intervals.
9. Prove Theorem 11.3. [Hint: To use Theorem 6.29, first show that ; P(Xi) < 1 implies that I
1-1 - ;P(Xi)! + I-I
+ ;p(xi)1 = 2.]
10. Show that if y E C 6 [a, b) and if wo, WI, ... , WN+I satisfy Eq. (11.18), then

where A is independent of h, provided q(x) > W > 0 on [a, bJ for some w.


11.4 finite-Difference Methodsfor Nonlinear Problems 667

11.4 Finite-Difference Methods for Nonlinear Problems


For the general nonlinear boundary-value problem

y" = I(x, y, y'), a:S x < b, yea) = a, y(b) = fl,

the difference method is similar to the method applied to linear problems in Section 11.3.
Here, however, the system of equations will not be linear, so an iterative process is required
to solve it.
For the development of the procedure, we assume throughout that f satisfies the fol-
lowing conditions:

1. f and the partial derivatives fy and fy' are all continuous on

D = {(x, y, y') Ia <x < b, -00 < y < 00, -00 < y' < oo};

2. fy (x , y, y') > 8 on D, for some 8 > 0;

3. Constants k and L exist, with

k = max Ify(x, y, Y')1 and L = max Ih(x, y. y')I.


(x,y,Y')ED (x,y,y')ED

This ensures, by Theorem 11.1, that a unique solution exists.


As in the linear case, we divide [a, b] into (N + 1) equal subintervals whose endpoints
are at Xi = a + i h, for i = 0, 1, ... , N + 1. Assuming that the exact solution has a bounded
fourth derivative allows us to replace y" (Xi) and y' (Xi) in each of the equations

by the appropriate centered-difference fOImula given in Eqs. (11.16) and (11.17). This
gives, for each i = 1, 2, . .. , N,
2
y(xi+d -: 2Y(Xi) + y(xi-d = f y(xi+d - Y(Xi-I) h '"
h2
Xi, y(Xj), 2h -6 Y (1]i)

for some ~i and 1]i in the interval (Xi-I, Xj+l).


As in the linear case, the difference method results when the error terms are deleted
and the boundary conditions are employed:

Wo = a, WN+l = fl,

and

Xi, Wi, = 0,
2h

for each i = 1, 2, . .. ,N.


668 C HAP T E R 11 • Boundary-Value Problemsfor Ordinary Differential Equations

The N x N nonlinear system obtained from this method,


2 W2 - Cl
2wI - W2 +h f XI, WI, 2h - Cl = 0,
2 W3 - WI
-WI + 2W2 - W3 +h f X2, W2, 2h = 0,


• (11.20)

= 0,
2h

2 f3 - WN-I
-WN-I+2wN+hf XN,WN, 2h -f3=0

has a unique solution provided that h < 2/ L, as shown in [Keller, H, p. 86].


We use Newton's method for nonlinear systems, discussed in Section 10.2, to ap-
proximate the solution to this system. A sequence of iterates {( w~k), wi ), ... , w~))'} is
k

generated that converges to the solution of system (11.20), provided that the initial appro x -
. .
ImatlOn (wI . suffi'
0 ) ' w (0) , ... , w (0))' IS clen tIy c Iose to the soIutlon
' ( WI, W2, ... , WN )' , and
2 N
that the Jacobian matrix for the system is nonsingular. For system (11.20), the Jacobian
matrix J(WI, ... , WN) is tridiagonal with ij-th entry

h Wi+1 - Wi-I
-1 + 2 fyl Xi, Wi,
2h
, for i = j - 1 and j = 2, . .. ,N,

2 Wi+! - Wi-!
2 +h fy Xi, Wi, 2h , for i = j and j = 1, ... , N,

h Wi+l - Wi-l
2 y / x'I ,
-1--/ W,I , 2h , for i = j + 1 and j = 1, . .. , N - 1,

where Wo = Cl and WN+l = f3.


Newton's method for nonlinear systems requires that at each iteration the N x N linear
system

J(Wl, ... ,WN)(VI, ... ,vn )'



W2 - Cl
,
2h

- WI + 2W2 - W3 +h f2
Xz, W2,
2h
, .. . ,

,
2h
,
-f3

be solved for VI, V2, ... , VN, since

w,~k) = w,(k-I) + V,' , "lor each i = 1, 2 , ... , N.


11.4 finite-Difference Methods for Nonlinear Problems 669

Since J is tridiagonal, this is not as fonnidable a problem as it might at first appear. The
Crout Factorization Algorithm (6.7) can be applied. The process is detailed in Algorithm
11.4.

Nonlinear Finite-Difference
To approximate the solution to the nonlinear boundary-value problem

y" = f(x, y, y'), a::S x < b, yea) = a, y(b) = f3 :

INPUT endpoints a, b; boundary conditions a, f3; integer N 2: 2; tolerance TOL; maxi-


mum number of iterations M.
OUTPUT approximations Wi to y(Xi) for each i = 0, 1, ... , N + lor a message that the
maximum number of iterations was exceeded.

Step 1 Set h = (b - a)/(N + 1);


Wo = a;
WN+I = f3.
f3-a
Step 2 For i = 1, ... , N set Wi = a +i h.
b-a
Step 3 Set k = 1.
Step 4 While k < M do Steps 5-16.
Step 5 Set x = a + h;
t = (W2 - a)/(2h);
al = 2 + h fy(x, WI, t);
2

b l = -1 + (h/2)h(x, WI, t);


d l = -(2wl - W2 - a + h 2 f(x, WI, t)).
Step 6 For i = 2, . .. ,N - 1
setx=a+ih;
t = (Wi+1 - Wi_I)/(2h);
ai = 2 + h 2fy(x, Wi, t);
b i = -1 + (h/2)h(x, Wi, t);
ci = -1 - (h/2)h(x, Wi, t);
di = -(2Wi - Wi+1 - Wi-I + h 2 f(x, Wi, t)).
Step 7 Set x = b - h;
t = (f3 - WN_I)/(2h);
aN = 2 + h 2 fy(X, WN, t);
CN = -1 - (h/2)h(x, WN, t);
d N = -(2WN - wN-1 - f3 + h 2f(x, WN, t)).
Step 8 Set II = al; (Steps 8-12 solve a tridiagonal linear system using
Algorithm 6.7.)
UI = bI/al;
ZI =dI/ll.
670 C HAP T E R 11 • Boundary-Value Problems for Ordinary Differential Equations

Step 9 For i = 2, ... , N - 1 set Ii = ai - CiUi-l;


Ui = hi! Ii;
Zi = (di - CiZi-I)/li .

Step 10 Set IN = aN - CNUN-I;


ZN = (dN - CNZN-I)/IN.

Step 17 Set vN= ZN;


wN = wN + VN.
Step 12 Fori = N -1, ... ,1 set Vi = Zi - UiVi+l;
Wi = Wi + Vi·

Step 13 If IIvll < TOL then do Steps 14 and 15.


Step 14 For i = 0, ... , N + 1 set x = a + ih;
OUTPUT (x, Wi).
Step 15 STOP. (The procedure was successful.)
Step 16 Set k = k+ 1.
Step 17 OUTPUT (,Maximum number of iterations exceeded');
(The procedure was unsuccessful.)
STOP.

It can be shown (see [IK, p. 433]) that this Nonlinear Finite-Difference method is of
order O(h2).
Since a good initial approximation is required when the satisfaction of conditions (1),
(2), and (3) given at the beginning of this presentation cannot be verified, an upper bound
for the number of iterations should be specified and, if exceeded, a new initial approxima-
tion or a reduction in step size considered. The initial approximations w~O) to Wi, for each
i = 1, 2, ... , N, are obtained in Step 2 by passing a straight line through (a, a) and (b, f3)
and evaluating at Xi.

EXAMPLE 1 We apply Algorithm 11.4, with h = 0.1, to the nonlinear boundary-value problem
1 3 43
y" = 8 (32 + 2x - yy'), 1 :::: x :::: 3, y(1) = 17, y(3) = 3'

giving the results in Table 11.5. The stopping procedure used in this example was to iterate
until values of successive iterates differed by less than 10- 8 . This was accomplished with
four iterations. The problem in this example is the same as that considered for the Nonlinear
Shooting method, Example 1 of Section 11.2. •

Richardson's extrapolation procedure can also be used for the Nonlinear Finite-
Difference method. Table 11.6 lists the results when this method is applied to our example
using h = 0.1,0.05, and 0.025, with four iterations in each case. The notation is the same
as in Example 2 of Section 11.3, and the values of Ext3i are all accurate to the places listed,
with an actual maximum error of 3.68 x 10- 10 . The values of wi(h = 0.1) are omitted
from the table, since they were listed previously.

You might also like