(Chapter 3) Finite Difference Method
(Chapter 3) Finite Difference Method
3.1 Introduction
In this chapter, we will develop finite difference technique for approxi-
mating the solution of the two-point boundary value problem (BVP),
The special case in which the value of the first derivative is specified
for example
y 0(x0) = λ and/or y 0 (xN ) = θ,
is called a Neumann boundary condition.
Example 3.1 Use finite difference method to solve the following bound-
ary value problems.
(i) y 00 + xy 0 + y = x2,
y(0) = 0, y(1) = 1, and h = 0.25.
1
(ii) (xy 0)0 + y = 1,
x
y(1) = 2, y(3) = 4, and h = 0.5.
or
y(x0) = α, y 0 (xN ) = θ, (3.10)
or
y 0 (x0) = λ, y 0(xN ) = θ. (3.11)
Finite difference algorithm to solve equation (3.4) with boundary con-
ditions (3.9).
Repeat step (i), (ii) and (iii) as in Dirichlet boundary condition, we
have
y − 2y + y y − y
i+1 i i−1 i+1 i−1
2
= p(x i ) + q(xi)yi + r(xi ),
h 2h
for i = 0, 1, 2, . . . , N − 1.
If i = 0, we have
y − 2y + y y − y
1 0 −1 1 −1
= p(x 0 ) + q(x0)y0 + r(x0 ). (3.12)
h2 2h
42 CHAPTER 3. FINITE DIFFERENCE METHOD
Example 3.4 Use finite difference method to solve the following bound-
ary value problems
(i) y 00 = y + x,
y 0(0) = 1, y(1) = 2, and h = 0.25.
(ii) xy 00 + y 0 + x = 0,
y(1) = 0, y 0(2) = 1, and h = 0.25.
(iii) y 00 + xy 0 + 2y = x,
y 0(1) = 0.5, y 0(2) = 0, and h = 0.25.
When i = 0, we have
y − 2y + y y − y
1 0 −1 1 −1
= p(x0) + q(x0)y0 + r(x0).
h2 2h
To eliminate y−1 , estimate first boundary condition
α2 − α0 y(x0)
y 0(x0 ) =
α1
using equation (3.6) with i = 0, we have
y1 − y−1 α2 − α0 y(x0)
=
2h α1
or
2h
y−1 = y1 − (α2 − α0 y0 )
α1
When i = N, we have
y
N +1 − 2yN + yN −1
y
N +1 − yN −1
= p(x N ) + q(xN )yN + r(xN ).
h2 2h
To eliminate yN +1 , estimate second boundary condition
β2 − β0 y(xN )
y 0(xN ) =
β1
yN +1 − yN −1 β2 − β0 y(x0)
=
2h β1
or
2h
yN +1 = yN −1 + (β2 − β0 y0)
β1
Finally find linear system of equations Ay = b, where y = (y0, y1,
y2 , . . . , yN −1, yN )T . Then solve the linear equation.
Example 3.5 Use finite difference method to solve the following bound-
ary value problems
44 CHAPTER 3. FINITE DIFFERENCE METHOD
(i) y 00 = y + x,
y(0) + y 0(0) = 0.5, y(1) − 2y 0 (1) = 0, and h = 0.25.
(ii) y 00 − y = 1,
1
y(0) − y 0(0) = 1, y(1) + y 0(1) = 1, and h = 0.25.
2
(iii) y 00 + xy 0 + y = x2,
y(0) + y 0(0) = 0, y(1) + y 0(1) = 1, and h = 0.25.
(i) the function f and its partial derivatives with respect to y and y 0
are continuous,
Example 3.6 Find the nonlinear F(y) = 0 when we solve the follow-
ing boundary value problems using finite difference method with step
size h = 0.25.
(i) y 00 + (y 0)2 = 1, 0 ≤ x ≤ 1,
y(0) = 1, y(1) = 2.
(ii) y 00 + 4xyy 0 + 2y 0 = 0, 0 ≤ x ≤ 1,
y(0) = 1, y(1) = 0.5.
y 00 + 2y 2 = 8x2 y 3, 0 ≤ x ≤ 1,
(i) Find the nonlinear system F(y) = 0 when we solve the problem
above using finite difference method with step size h = 0.25.
(ii) Solve the nonlinear system in part (i) using Newton’s method
with initial vector y(0) = 0 and apply stopping criteria ||y(k+1) −
y(k)||∞ < 0.005.
yy 00 + (y 0)2 + 1 = 0, 1 ≤ x ≤ 2,
y(1) = 1, y(2) = 2.
46 CHAPTER 3. FINITE DIFFERENCE METHOD
(i) Find the nonlinear system F(y) = 0 when we solve the problem
above using finite difference method with step size h = 0.25.
(ii) Solve the nonlinear system in part (i) using Newton’s method
starting with y(0) = (1, 1, 1)T and stop your iteration when ||y(k+1)−
y(k)||∞ < 0.005.
If i = 0, we have
y1 − 2y0 + y−1 y1 − y−1
= f x0 , y0 , (3.15)
h2 2h
Estimate boundary condition y 0 (x0) = λ using equation (3.6) with i =
0, we have
y−1 = y1 − 2hλ
substitute y−1 = y1 − 2hλ into equation (3.15). Then find nonlinear
system
F(y) = 0,
where y = (y0, y1 , . . . , yN −1)T .
yy 00 = y 0 − 1, 1 ≤ x ≤ 2,
3.3. NONLINEAR TWO-POINT BOUNDARY VALUE PROBLEM47
y(1) = 0, y 0(2) = 1 + ln 2,
(i) Find the nonlinear system F(y) = 0 when we solve the problem
above using finite difference method with step size h = 0.5.
(ii) Solve the nonlinear system in part (i) using Newton’s method
starting with y(0) = (0.5, 0)T and stop your iteration when ||y(k+1)−
y(k)||∞ < 0.005.
y 00 + 2y 2 − 8x2 y 3 = 0, 0 ≤ x ≤ 1,
(i) Find the nonlinear system F(y) = 0 when we solve the problem
above using finite difference method with step size h = 0.5.
(ii) Solve the nonlinear system in part (i) using Newton’s method
starting with y(0) = (0, 0)T and stop your iteration when ||y(k+1) −
y(k)||∞ < 0.005.
y 0(1) = 4, y 0 (2) = 6.
(i) Find the nonlinear system F(y) = 0 when we solve the problem
above using finite difference method with step size h = 0.5.
y 00 = f(x, y, y 0), x0 ≤ x ≤ xN ,
Example 3.15 For the following boundary value problems, find the
system of nonlinear equation F(y) = 0 if we approximate the solution
using finite difference method.
2y
(i) y 00 + 4yy 0 + = 0, 0 ≤ x ≤ 1,
(1 + x2 )
y(0) + y 0(0) = 1, y 0(1) = 0, h = 0.25.
(ii) y 00 + 4xyy 0 + 2y 2 = 0, 0 ≤ x ≤ 1,
y(0) + y (0) = 1, y(1) + y 0(1) = 0, h = 0.25.
0
d2 u
+ Q(x) = 0, 0 ≤ x ≤ L,
dx2
du(0) du(L)
= 0, = 0.
dx dx
(i) If L = 2 and stepsize h = 0.5, find the nonlinear system F(u) = 0
using finite difference method.
(ii) Compute u(1) using Newton’s method starting with u(0) = (1, 1, 1, 1, 1)T .
(Hint: Write −[J (u(k))]−1 F(u(k) ) = w(k) , then solve the corre-
sponding linear system using Doolittle decomposition method).