You are on page 1of 15

San Jose State University

Department of Mechanical and Aerospace Engineering


ME 130 Applied Engineering Analysis
Instructor: Tai-Ran Hsu, Ph.D.
Chapter 9
Introduction to
Finite Difference Method for
Solving Differential Equations
Chapter Outline
What is finite difference method, and why?
Principle of finite difference method
The three basic finite difference schemes
Application in solution of difference equations
What is finite difference method, and why?
As we learned from Chapter 2, many engineering analysis using mathematical
modeling involve solutions of differential equations.
We learned the solution of first order differential equation in Chapter 3 in
the following way:
) ( ) ( ) (
) (
x g x u x p
dx
x du
= +
(3.6)
The solution is:

+ =
) (
) ( ) (
) (
1
) (
x F
K
dx x g x F
x F
x u (3.7)
in which

=
dx x p
e x F
) (
) (
(3.5)
For second order differential equation of the form:
0 ) (
) ( ) (
2
2
= + + x bu
dx
x du
a
dx
x u d
(4.1)
We have the solutions derived for three cases with Case 1 for a
2
-4b>0,
Case 2 for a
2
-4b<0, And Case 3 for a
2
-4b =o, as presented in Section 4.1
We are able to derive solutions for these differential equations which we classified to
be: LINEAR and HOMOGENEOUS differential equations
While many engineering problems can be described by these linear and homogeneous
differential equations as we have demonstrated in Chapters 3 and 4, there many other
types of engineering problems that can be modeled by NONLINEAR and
NONHOMOGENEOUS differential equations in the following distinct forms:
u+ Sinx = 0, uu = 1 u + u = 0, u+2u+ u = 0
u + 1/u = 0, u + u
2
= 0 u = 1/x
Nonlinear DEs Linear DEs
u+xu = x+x
2
u+xu= 0
u+2u+u = Sinx u+2u+u=0
Nonhomogeneous DEs Homogeneous DEs
(source: www.myphysicslab.com)
In the above Tables: the required solution is function u(x), and
( )
dx
x du
u = '
and
( )
2
2
"
dx
x u d
u =
Many advanced engineering analyses involve nonlinear and nonhomogeneous
differential equations, and solution of these equations often is beyond the reach by
classical methods as presented in Chapters 3 and 4.
Numerical solution method such as Finite Difference methods are often the only
practical and viable ways to solve these differential equations.
What we will learn in this chapter is the fundamental principle of this method, and
the basic formulations for solving ordinary differential equations
Principle of finite difference method
We have learned in Chapter 2 that differential equations are the equations that
involve derivatives.
Physically, a derivative represents the rate of change of a physical quantity
represented by a function with respect to the change of its variable(s):
f(x)
f(x)
x
x
i-1
x
i+1
x
i
x x
f
i+1
f
i
f
i-1
0
A
A
A
a
a
a
x = h, the step size
Tangent of f(x)
at x = x
i
Here, the function f(x) is graphically
Shown, with the function evaluated
At 3 consecutive variable x:
f
i+1
at x = x
i+1
f
i
at x = x
i
, and
f
i-1
at x = x
i-1
Since x
i+1
= x + x, and
x
i-1
= x x, we will have:
( )
x
f
x
f
im
dx
x df
x

=
0
l
(9.2)
Equation (9.3) depicts the principle of finite difference. It is important to be aware of the fact
that smaller the steps x the closer the values between the differential and difference of
the rate change of the function
x
f
dx
x df

) (
The differential The difference (9.3)
There are 3 ways to express differentials of a function f(x):
The forward difference scheme:
f(x)
f(x)
x
x
i-1
x
i+1
x
i
x x
f
i+1
f
i
f
i-1
0
A
A
A
a
a
a
x = h, the step size
Tangent of f(x)
at x = x
i
The rate of the change of the function with
respect to the variable x is accounted for
between the current value at:
x = x
i
and the step forward at
x
i+1
= x + x
Mathematical expression of the derivative
of the function f(x) is:
h
f f
x
f f
x x
f f
x
f
dx
x df
f
i i i i
i i
i i
x x x x
i
i i

=
+ +
+
+
= =
1 1
1
1
) (
(9.4)
where h = x = the incremental step size
Three Basic Finite Difference Schemes
f(x)
f(x)
x
x
i-1
x
i+1
x
i
x x
f
i+1
f
i
f
i-1
0
A
A
A
a
a
a
x = h, the step size
Tangent of f(x)
at x = x
i
The forward difference scheme- Contd:
The derivative of the function at other values
of the variable x in the positive direction can be
expressed following Equation (9.4) are:
. ,
2 3
2
1 2
1
etc
h
f f
f
h
f f
f
i i
i
i i
i
+ +
+
+ +
+

=
(9.5)
The second order derivative of the function at x can be derived by the following procedure
2
1 2
1 1 2
1 1
0
2
2
) (
1
h
f f f
h
h
f f
h
f f
h
f f
x
f f
x
f f
im
dx
x df
dx
d
f
i i i
i i i i
i i i i
i
x
x
x x
i
i
i
+
=

=

=

=
+ +
+ + +
+ +

=
+
l
(9.6)
The backward difference scheme:
f(x)
f(x)
x
x
i-1
x
i+1
x
i
x x
f
i+1
f
i
f
i-1
0
A
A
A
a
a
a
x = h, the step size
Tangent of f(x)
at x = x
i
We evaluate the rate of change of the
function values between the current step
at x
i
, and the function value at a step back
at x
i-1
, i.e. x = x x.
Mathematically, we will have the following:
h
f f
x
f f
x
x x f x f
im
x
f f
im f
i i i i
x
i i
x
i
1 1
0
1
0
) ( ) (

= l l (9.7)
and the send order derivatives in the form:
2
2 1 2
2
h
f f f
f
i i i
i

+

(9.8)
The central difference scheme:
f(x)
f(x)
x
x
i-1
x
i+1
x
i
x x
f
i+1
f
i
f
i-1
0
A
A
A
a
a
a
x = h, the step size
Tangent of f(x)
at x = x
i
The rate of change of function f(x) is
accounted for between the step at back
at (x-x) and the step ahead of x, i.e. (x+x).
From the graphical representation
we have:
h
f f
x x
f f
f
i i
i i
i i
i
2
1 1
1 1
1 1 +
+
+

=

(9.9)
The step size in Equation (9.9) is 2h which
is big in compromising the accuracy.
A more accurate central difference scheme is
to reduce the step size in each forward and
backward direction by half as show
f(x)
f(x)
x
x
i-1
x
i+1
x
i
x x
f
i+1
f
i
f
i-1
0
A
A
A
a
a
a
x = h, the step size
Tangent of f(x)
at x = x
i
f
i+1/2
f
i-1/2
We will have the corresponding expressions:
h
f f
f
i i
i
2
1
2
1
+

=
(9.11)


+ =
+
2 2
2
1
2
1
x
x f f and
x
x f f
i i
where
Example on using finite difference method solving a differential equation
The differential equation and given conditions:
0 ) (
) (
2
2
= + t x
t
d
t x
d
(9.12)
1 ) 0 ( = x
with
and
0 ) 0 ( = x&
(9.13a, b)
Let us use the forward difference scheme in the solution with:
t
t x t t x
dt
t dx

+
=
) ( ) ( ) (
and
2 2
2
) (
) ( ) ( 2 ) 2 ( ) (
t
t x t t x t t x
t
d
t x
d

+ + +
=
(9.14a)
(9.14b)
We are now ready to convert the differential equation in (9.12) into the form of
difference equation by substituting the expressions in Equation (9.14b) into
Equation (9.12):
0 ) (
) (
) ( ) ( 2 ) 2 (
2
= +

+ + +
t x
t
t x t t x t t x
The following recurrence relationship is established by re-arranging the terms in the
the above difference equation:
0 ) ( ] ) ( 1 [ ) ( 2 ) 2 (
2
= + + + + t x t t t x t t x
(9.15)
Solution of Equation (9.12) with conditions in Equation (9.13) by classical method is:
x(t) = Cos(t)
Solution of DE in Equation (9.12) with conditions in Equation (9.13a,b)
The recurrence relation:
0 ) ( ] ) ( 1 [ ) ( 2 ) 2 (
2
= + + + + t x t t t x t t x
(9.15)
with the given conditions: x(0) = 1
( )
( ) ( ) ( )
0 0 0
0 0
=

+
= = =
= = t t
t
t x t t x
dt
t dx
x&
(9.13a)
and
9.13b)
From the second part of Equation (9.13b), we have the following relationship:
( ) ( )
( ) ( ) ( ) ( ) 0 0 0
0 0
x t x x t x
t
x t x
= =

+
Consequently, we have: x(t) = 1
(9.16b)
The recurrence relationship in Equation (9.15) will get us the function values at variable t,
with conditions in Equation (9.13a) and (9.16b) as the starting points.
We must choose the step size t for our numerical values of the function x(t).
the smaller the step size we choose, the more accurate the numerical values
we will get.
smaller steps means more computational effort in the solution process.
Let us choose a step size of t = 0.05:
The recurrence relation in Equation (9.15) becomes:
x(t+0.1) 2x(t+0.05) + 1.0025x(t) = 0
(a)
with x(0.05) = 1 from Equation (9.16b)
Now, we are ready to proceed finding the function values at other values of t.
At t = 0
From Equation (a): x(0.1) 2x(0.05) + 1.0025x(0) = 0
But since x(0) =1 in Equation (9.13a), we will get from the above expression:
x(0.1) 2 x(0.05) = -1.0025
=1 from Equation (9.16b)
Hence x(0.1) = -1.0025 + 2x(0.05) = 0.9975 (c)
- a numerical solution of function xt) at t = 0.1
At t = t+t = 0+0.05 = 0.05
The recurrence relationship in Equation (a) becomes:
x(0.05+0.1) 2x(0.05 + 0.05) + 1.0025x(0.05) = 0
or
x(0.15) 2 x(0.1) + 1.0025x(0.05) = 0 (d)
= 0.9975 from last step in Equation (d)
We will have: x(0.15) = 2x0.9975 1.0025x1 = 0.9925 (e)
Numerical solution for x(0.15)
At t = t+t = 0.05+0.05 = 0.1
By substituting t = 0.1 into x(t+0.1) 2x(t+0.05) + 1.0025x(t) = 0, we will get:
x(0.2) 2 x(0.15) + 1.0025x(0.1) = 0
= 0.9925 from last step
We will have x(0.2) = 2x0.9925 1.0025x0.9975 = 0.9850
Numerical solution of x(0.2)
The same solution procedure continues.
The numerical solution of x(t) obtained by the finite difference method is compared
With the exact solution obtained by classical solution in this example as follows:
0.503 0.980066 0.9850 0.20
0.38 0.98877 0.9925 0.15
0.25 0.9950041 0.9975 0.10
0 0.999996 1 0.05
0 1 1 0
% Error Exact Values Finite Difference Results Variable, t
Observations:
1) The error of the numerical solution increases with number of steps.
2) These error are referred to as accumulative errors
3) Step size definitely has strong effects on the accuracy of finite difference method
4) Trade-off between step size and computational effort is an issue in any
numerical technique such as finite difference method

You might also like