Вы находитесь на странице: 1из 10

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),

y 00 = f(x, y, y 0), x0 ≤ x ≤ xN , (3.1)

with boundary conditions

α0 y(x0) + α1y 0 (x0) = α2,


(3.2)
β0y(xN ) + β1y 0 (xN ) = β2,

where f is an arbitrary function of its three arguments. When f is of


the form
f(x, y, y 0) = p(x)y 0 + q(x)y + r(x), (3.3)
for some functions p, q and r, the boundary value problem is called
linear, otherwise it is nonlinear. The boundary condition (3.2) is called
Robin boundary condition.
The special case in which the value of unknown function is specified
for example
y(x0) = α and y(xN ) = β,
is called Dirichlet boundary condition.
40 CHAPTER 3. FINITE DIFFERENCE METHOD

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.

3.2 Linear Two-point Boundary Value Prob-


lem
3.2.1 Dirichlet Boundary Conditions
Consider linear second order differential equation.
y 00 = p(x)y 0 + q(x)y + r(x), x0 ≤ x ≤ xN , (3.4)
with Dirichlet boundary conditions
y(x0) = α, y(xN ) = β. (3.5)
Finite difference algorithm to solve equation (3.4) with boundary con-
dition (3.5).
(i) Divide interval [x0, xN ] into N subintervals whose endpoints are
at xi = x0 + ih, i = 0, 1, 2, . . . , N where h is a stepsize.
(ii) Approximate yi0 and yi00 using 3 point centered difference formulae,
yi+1 − yi−1
yi0 ≈ , (3.6)
2h
and
yi+1 − 2yi + yi−1
yi00 ≈ . (3.7)
h2
(iii) Substitute formula (3.6) and (3.7) into (3.4). Estimate the solu-
tion at x = xi , i = 1, 2, . . . , N − 1. First write
yi00 = p(xi )yi0 + q(xi )yi + r(xi ).
Then estimate yi0 and yi00 using (3.6) and (3.7), we have
 y − 2y + y  y − y 
i+1 i i−1 i+1 i−1
2
= p(xi ) +q(xi )yi +r(xi ), (3.8)
h 2h
for i = 1, 2, 3, . . . , N − 1.
3.2. LINEAR TWO-POINT BOUNDARY VALUE PROBLEM 41

(iv) Find linear system of equations Ay = b, where A is (N − 1) ×


(N − 1) and tridiagonal matrix. Then solve the linear system of
equations.

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.

3.2.2 Neumann Boundary Conditions


Consider equation (3.4) with boundary conditions,

y 0(x0 ) = λ, y(xN ) = β (3.9)

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

Estimate boundary condition y 0 (x0) = λ using equation (3.6) with i =


0, we have
y1 − y−1
= λ,
2h
or
y−1 = y1 − 2hλ. (3.13)
Then substitute (3.13) into (3.12). Find linear system of equations
Ay = b, where y = (y0 , y1, . . . , yN −1)T .

Example 3.2 Write an algorithm to solve equation (3.4) with bound-


ary condition (3.10) using finite difference method.

Example 3.3 Write an algorithm to solve equation (3.4) with bound-


ary condition (3.11) using 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.

3.2.3 Robin Boundary Conditions


Consider (3.4) with boundary conditions (3.2).
Repeat step (i),(ii), and (iii), we have
y − 2yi + yi−1  y − y 
i+1 i+1 i−1
2
= p(xi ) + q(xi)yi + r(xi ),
h 2h
i = 0, 1, 2, . . . , N − 1.
3.2. LINEAR TWO-POINT BOUNDARY VALUE PROBLEM 43

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

using equation (3.6) with i = N, we have

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.

3.3 Nonlinear Two-point Boundary Value


Problem
The nonlinear differential equation (3.1) with boundary equation (3.2)
has a unique solution provided that,

(i) the function f and its partial derivatives with respect to y and y 0
are continuous,

(ii) the partial derivative of f with respect to y is positive, and

(iii) the partial derivative of f with respect to y 0 is bounded.

3.3.1 Dirichlet Boundary Conditions


Finite difference algorithm to solve equation (3.1) with boundary con-
dition (3.5).

(i) Divide interval [x0, xN ] into N subintervals whose endpoints are


at xi = x0 + ih, i = 0, 1, 2, . . . , N where h is a step size.

(ii) Estimate the solution at x = xi , i = 1, 2, . . . , N − 1. Then ap-


proximate yi0 and yi00 using 3 points centered difference formulae
(3.6) and (3.7).
3.3. NONLINEAR TWO-POINT BOUNDARY VALUE PROBLEM45

(iii) Substitute formula (3.6) and (3.7) into (3.1), we obtain


yi+1 − 2yi + yi−1  yi+1 − yi−1 
= f x ,
i iy ,
h2 2h (3.14)
i = 1, 2, . . . , N − 1.

(iv) Solve nonlinear system F(y) = 0 where y = (y1 , y2, . . . , yN −1)T .

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.

Example 3.7 Consider the nonlinear differential equation,

y 00 + 2y 2 = 8x2 y 3, 0 ≤ x ≤ 1,

with boundary conditions

y(0) = 1, y(1) = 0.5.

(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.

Example 3.8 Given the following boundary value problem,

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.

3.3.2 Neumann Boundary Conditions


Consider equation (3.1) with boundary conditions (3.9). Repeat step
(i),(ii) and (iii), we have
yi+1 − 2yi + yi−1  yi+1 − yi−1 
= f x i , y i ,
h2 2h
i = 0, 1, 2, . . . , N − 1.

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 .

Example 3.9 Write an algorithm to solve equation (3.1) with bound-


ary condition (3.10) using finite difference method.

Example 3.10 Write an algorithm to solve equation (3.1) with bound-


ary condition (3.11) using finite difference method.

Example 3.11 Consider the nonlinear differential equation,

yy 00 = y 0 − 1, 1 ≤ x ≤ 2,
3.3. NONLINEAR TWO-POINT BOUNDARY VALUE PROBLEM47

with boundary conditions

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.

Example 3.12 Consider the nonlinear differential equation,

y 00 + 2y 2 − 8x2 y 3 = 0, 0 ≤ x ≤ 1,

with boundary conditions

y 0(0) = 1, y(1) = −0.5, h = 0.5.

(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.

Example 3.13 Consider the nonlinear differential equation,

2xy 00 + (y 0)2 − 4y = 4x, 1 ≤ x ≤ 2,

with boundary conditions

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.

(ii) Compute y(2) using Broyden’s method if initial vector y(0) =


(1, 1, 1)T .
48 CHAPTER 3. FINITE DIFFERENCE METHOD

3.3.3 Robin Boundary Conditions


Example 3.14 Consider the nonlinear differential equation,

y 00 = f(x, y, y 0), x0 ≤ x ≤ xN ,

α0 y(x0) + α1 y 0(x0 ) = α2 , β0 y(x0) + β1 y 0(x0 ) = β2.


Write an algorithm to solve the problem above using finite difference
method.

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

Example 3.16 The steady-state temperature distribution for a rod of


 2πx 
length L, with source term Q(x) = sin and insulated ends leads
L
to the following boundary value problem,

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).

Вам также может понравиться