chapter 9 intro to fdm

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

Upload: giannis-giorgos

Post on 27-Nov-2015

23 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Chapter 9 Intro to FDM

San Jose State UniversityDepartment 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

Page 2: Chapter 9 Intro to FDM

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

Page 3: Chapter 9 Intro to FDM

What is finite difference method, and why?

● As we learned from Chapter 2, many engineering analysis using mathematicalmodeling involve solutions of differential equations.

● We learned the solution of first order differential equation in Chapter 3 inthe following way:

)()()()( xgxuxpdx

xdu=+ (3.6)

The solution is:∫ +=

)()()(

)(1)(

xFKdxxgxF

xFxu (3.7)

in which ∫=dxxp

exF)(

)((3.5)

● For second order differential equation of the form:

0)()()(2

2

=++ xbudx

xduadx

xud (4.1)

We have the solutions derived for three cases with Case 1 for a2-4b>0, Case 2 for a2-4b<0, And Case 3 for a2-4b =o, as presented in Section 4.1

Page 4: Chapter 9 Intro to FDM

● We are able to derive solutions for these differential equations which we classified tobe: 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 othertypes of engineering problems that can be modeled by NONLINEAR andNONHOMOGENEOUS differential equations in the following distinct forms:

u”+ Sinx = 0, uu’ = 1u” + u = 0, u”+2u’+ u = 0

u’ + 1/u = 0, u’ + u2 = 0u’ = 1/x

Nonlinear DEsLinear DEs

u’+xu = x+x2u’+xu= 0

u”+2u’+u = Sinxu”+2u’+u=0

Nonhomogeneous DEsHomogeneous DEs

(source: www.myphysicslab.com)

In the above Tables: the required solution is function u(x), and ( )dx

xduu ='

and( )2

2

"dx

xudu =

Page 5: Chapter 9 Intro to FDM

● Many advanced engineering analyses involve nonlinear and nonhomogeneousdifferential equations, and solution of these equations often is beyond the reach byclassical 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

Page 6: Chapter 9 Intro to FDM

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)

xxi-1 xi+1xi

∆x ∆x

fi+1

fifi-1

0

A’’

A

A’

a’

a”a’’’

∆x = h, the step size Tangent of f(x) at x = xiHere, the function f(x) is graphically

Shown, with the function evaluatedAt 3 consecutive variable x:

fi+1 at x = xi+1 fi at x = xi, andfi-1 at x = xi-1

Since xi+1 = x + ∆x, and xi-1 = x – ∆x, we will have:

( )xf

xfim

dxxdf

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

xf

dxxdf

∆∆

≈)(The “differential” The “difference” (9.3)

Page 7: Chapter 9 Intro to FDM

There are 3 ways to express differentials of a function f(x):

● The “forward difference scheme”:

f(x)

f(x)

xxi-1 xi+1xi

∆x ∆x

fi+1

fifi-1

0

A’’

A

A’

a’

a”a’’’

∆x = h, the step size Tangent of f(x) at x = xi

The rate of the change of the function with respect to the variable x is accounted for between the current value at:

x = xi and the step forward atx i+1 = x + ∆x

Mathematical expression of the derivativeof the function f(x) is:

hff

xff

xxff

xf

dxxdff iiii

ii

ii

xxxxi

ii

−=

∆−

=−−

=∆∆

≈=∇ ++

+

+

==

11

1

1)((9.4)

where h = ∆x = the incremental step size

Three Basic Finite Difference Schemes

Page 8: Chapter 9 Intro to FDM

f(x)

f(x)

xxi-1 xi+1xi

∆x ∆x

fi+1

fifi-1

0

A’’

A

A’

a’

a”a’’’

∆x = h, the step size Tangent of f(x) at x = xi

● The “forward difference scheme”- Cont’d:

The derivative of the function at other values of the variable x in the positive direction can be expressed following Equation (9.4) are:

.,232

121

etch

fff

hff

f

iii

iii

+++

+++

−=∇

−=∇

(9.5)

The second order derivative of the function at x can be derived by the following procedure

212

112

11

0

2

2

)( 1

hfff

hh

ffh

ff

hff

xff

x

ffim

dxxdf

dxdf

iii

iiii

iiiiix

xxx

ii

i

+−=

−−

=

∇−∇=

∆∇−∇

≈∆

∇−∇=⎟

⎠⎞

⎜⎝⎛=∇

++

+++

++

→∆=

+l

(9.6)

Page 9: Chapter 9 Intro to FDM

● The “backward difference scheme”:

f(x)

f(x)

xxi-1 xi+1xi

∆x ∆x

fi+1

fifi-1

0

A’’

A

A’

a’

a”a’’’

∆x = h, the step size Tangent of f(x) at x = xi

We evaluate the rate of change of thefunction values between the “current” step at xi, and the function value at a step “back”at xi-1, i.e. x = x – ∆x.

Mathematically, we will have the following:

hff

xff

xxxfxfim

xff

imf iiii

x

ii

xi11

0

1

0

)()( −−

→∆

→∆

−=

∆−

≈∆

∆−−=

∆−

=∇ ll (9.7)

and the send order derivatives in the form:

2212 2

hfff

f iiii

−− +−≈∇ (9.8)

Page 10: Chapter 9 Intro to FDM

● The “central difference scheme”:

f(x)

f(x)

xxi-1 xi+1xi

∆x ∆x

fi+1

fifi-1

0

A’’

A

A’

a’

a”a’’’

∆x = h, the step size Tangent of f(x) at x = xi

The rate of change of function f(x) is accounted for between the step at backat (x-∆x) and the step ahead of x, i.e. (x+∆x).

From the graphical representationwe have:

hff

xxff

f ii

ii

iii 2

11

11

11 −+

−+

−+ −=

−−

≈∇ (9.9)

The step size in Equation (9.9) is “2h” whichis “big” in compromising the accuracy.

A more accurate “central difference scheme” is to reduce the step size in each forward andbackward direction by half as show

f(x)

f(x)

xxi-1 xi+1xi

∆x ∆x

fi+1

fifi-1

0

A’’

A

A’

a’

a”a’’’

∆x = h, the step size Tangent of f(x) at x = xi

fi+1/2fi-1/2

We will have the corresponding expressions:

h

fff

ii

i21

21

−+−

≈=∇(9.11)

⎟⎠⎞

⎜⎝⎛ ∆

−=⎟⎠⎞

⎜⎝⎛ ∆

+=−+ 22 2

121

xxffandxxffii

where

Page 11: Chapter 9 Intro to FDM

Example on using finite difference method solving a differential equation

The differential equation and given conditions:

0)()(2

2=+ tx

tdtxd

(9.12)

1)0( =xwith and 0)0( =x& (9.13a, b)

Let us use the “forward difference scheme” in the solution with:

ttxttx

dttdx

∆−∆+

=)()()(

and 22

2

)()()(2)2()(

ttxttxttx

tdtxd

∆+∆+−∆+

=

(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) intoEquation (9.12):

0)()(

)()(2)2(2 =+

∆+∆+−∆+ tx

ttxttxttx

The following recurrence relationship is established by re-arranging the terms in the the above difference equation:

0)(])(1[)(2)2( 2 =∆++∆+−∆+ txtttxttx (9.15)

Solution of Equation (9.12) with conditions in Equation (9.13) by classical method is:x(t) = Cos(t)

Page 12: Chapter 9 Intro to FDM

Solution of DE in Equation (9.12) with conditions in Equation (9.13a,b)

The recurrence relation: 0)(])(1[)(2)2( 2 =∆++∆+−∆+ txtttxttx (9.15)

with the given conditions: x(0) = 1

( ) ( ) ( ) ( ) 00000

=∆

−∆+===

== tt ttxttx

dttdxx&

(9.13a)

and9.13b)

From the second part of Equation (9.13b), we have the following relationship:( ) ( ) ( ) ( ) ( ) ( )00000 xtxxtx

txtx

=∆⇒−∆⇒=∆

−∆+

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.

Page 13: Chapter 9 Intro to FDM

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) = 0But 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

Page 14: Chapter 9 Intro to FDM

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 stepWe will have x(0.2) = 2x0.9925 – 1.0025x0.9975 = 0.9850

Numerical solution of x(0.2)

Page 15: Chapter 9 Intro to FDM

The same solution procedure continues.

The numerical solution of x(t) obtained by the finite difference method is comparedWith the exact solution obtained by classical solution in this example as follows:

0.5030.9800660.98500.20

0.380.988770.99250.15

0.250.99500410.99750.10

≈00.99999610.05

0110

% ErrorExact ValuesFinite Difference ResultsVariable, 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 method4) Trade-off between step size and computational effort is an issue in any

numerical technique such as finite difference method