0% found this document useful (0 votes)
112 views9 pages

ME 261-Lecture 18 - July 2016

The document discusses numerical differentiation using finite difference methods. It introduces forward and central finite difference formulas to approximate derivatives to varying orders of accuracy. The central difference formula is presented to calculate derivatives to orders O(h^2) using two points, O(h^4) using three points, and higher orders using additional points. Taylor series expansions are used to derive the central difference formulas.

Uploaded by

shihab
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)
112 views9 pages

ME 261-Lecture 18 - July 2016

The document discusses numerical differentiation using finite difference methods. It introduces forward and central finite difference formulas to approximate derivatives to varying orders of accuracy. The central difference formula is presented to calculate derivatives to orders O(h^2) using two points, O(h^4) using three points, and higher orders using additional points. Taylor series expansions are used to derive the central difference formulas.

Uploaded by

shihab
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/ 9

ME 261: Numerical Analysis

Dr. A.B.M. Toufique Hasan


Professor
Department of Mechanical Engineering, BUET

Term: July 2016


04 December 2016

Lecture-18:
Numerical Differentiation
(Finite Difference Method)

http://teacher.buet.ac.bd/toufiquehasan/courses.php
[email protected]

L2 T2: July 2016

ME 261: Numerical Analysis

Forward difference formulation


shown in last class
f ′( xi ) = ? h
dy →x
f ′( xi ) / :
dx x = xi i i +1 i+2 i+3
f ( xi ) f ( xi +1 ) f ( xi + 2 ) f ( xi + 3 )

f ( xi +1 ) − f ( xi ) Forward difference formulation


f ′( xi ) = + O ( h)
h
1st order, O (h) approximat ion of f ′( xi ) using forward difference formula

− f ( xi + 2 ) + 4 f ( xi +1 ) − 3 f ( xi )
f ′( xi ) = + O (h 2 )
2h

2nd order, O (h 2 ) approximat ion of f ′( xi ) using forward difference formula

2 f ( xi + 3 ) − 9 f ( xi + 2 ) + 18 f ( xi +1 ) − 11 f ( xi )
f ′( xi ) = + O (h 3 )
6h

3rd order, O ( h 3 ) approximat ion of f ′( xi ) using forward difference formula

ME 261: Numerical Analysis 2

1
Central Finite Difference Formula
First derivative: O(h2) f ′( xi ) = ? h

dy →x
f ′( xi ) / : i i +1 i + 2 (1 − D )
dx i−2 i −1
x = xi
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central Finite Difference Formula:
Central difference formulation
f ( xi +1 ) can be approximat ed using Taylor series expansion -
f ′′( xi ) 2 f ′′′( xi ) 3 f n ( xi ) n
f ( xi +1 ) = f ( xi ) + f ′( xi )h + h + h + ... ... ... + h + O ( h n +1 )
2! 3! n!
f ′′( xi ) 2
⇒ f ( xi +1 ) ≈ f ( xi ) + f ′( xi )h + h + O(h 3 ) (i )
2!
Similarly, f ( xi −1 ) can be approximat ed using Taylor series expansion -
f ′′( xi ) 2 f ′′′( xi ) 3 f n ( xi ) n
f ( xi −1 ) = f ( xi ) − f ′( xi )h + h − h + ... ... ... + h + O ( h n +1 )
2! 3! n!
f ′′( xi ) 2
⇒ f ( xi −1 ) ≈ f ( xi ) − f ′( xi )h + h + O( h 3 ) (ii )
2!
Now, Eqn. (i) - Eqn.(ii) gives -
f ( xi +1 ) − f ( xi −1 ) = 2 f ′( xi )h + O(h 3 )
f ( xi +1 ) − f ( xi −1 )
⇒ f ′( xi ) = + O(h 2 ) O(h2) using 2 points xi+1 and xi-1
2h
2nd order, O ( h 2 ) approximat ion of f ′( xi ) using central difference formula
ME 261: Numerical Analysis 3

Central Finite Difference Formula cont…


First derivative: O(h4) f ′( xi ) = ? h

dy →x
f ′( xi ) / : i i +1 i + 2 (1 − D )
dx i−2 i −1
x = xi
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central Finite Difference Formula: Central difference formulation

f ( xi +1 ) can be approximat ed using Taylor series expansion -


f ′′( xi ) 2 f ′′′( xi ) 3 f IV ( xi ) 4 f n ( xi ) n
f ( xi +1 ) = f ( xi ) + f ′( xi )h + h + h + h + ... ... ... + h + O ( h n +1 )
2! 3! 4! n!
f ′′( xi ) 2 f ′′′( xi ) 3 f IV ( xi ) 4
⇒ f ( xi +1 ) ≈ f ( xi ) + f ′( xi ) h + h + h + h + O(h 5 ) (i )
2! 3! 4!
Similarly, f ( xi −1 ) can be approximat ed using Taylor series expansion -
f ′′( xi ) 2 f ′′′( xi ) 3 f IV ( xi ) 4 f n ( xi ) n
f ( xi −1 ) = f ( xi ) − f ′( xi )h + h − h + h − ... ... ... + h + O ( h n +1 )
2! 3! 4! n!
f ′′( xi ) 2 f ′′′( xi ) 3 f IV ( xi ) 4
⇒ f ( xi −1 ) ≈ f ( xi ) − f ′( xi )h + h − h + h + O (h 5 ) (ii )
2! 3! 4!
Eqn. (i)-Eqn. (ii):
2 f ′′′( xi ) 3
f ( xi +1 ) − f ( xi −1 ) = 2 f ′( xi )h + h + O(h5 ) (iii )
3!

ME 261: Numerical Analysis 4

2
Central Finite Difference Formula cont…
f ′( xi ) = ? h

→x
i−2 i −1 i i +1 i + 2 (1 − D )
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central difference formulation

f ( xi + 2 ) can be approximated using Taylor series expansion -


f ′′( xi ) f ′′′( xi ) f IV ( xi ) f n ( xi )
f ( xi + 2 ) = f ( xi ) + f ′( xi )(2h) + ( 2 h) 2 + (2 h ) 3 + (2h) 4 + ... ... ... + (2h) n + O (h n +1 )
2! 3! 4! n!
f ′′( xi ) f ′′′( xi ) f IV ( xi )
⇒ f ( xi + 2 ) ≈ f ( xi ) + f ′( xi )( 2h) + ( 2h ) 2 + ( 2h ) 3 + ( 2 h) 4 + O(h 5 ) (iv)
2! 3! 4!

Similarly, f ( xi − 2 ) can be approximated using Taylor series expansion -


f ′′( xi ) f ′′′( xi ) f IV ( xi ) f n ( xi )
f ( xi − 2 ) = f ( xi ) − f ′( xi )(2h) + ( 2 h) 2 − ( 2h) 3 + ( 2h) 4 − ... ... ... + ( 2h ) n + O ( h n + 1 )
2! 3! 4! n!
f ′′( xi ) f ′′′( xi ) f IV ( xi )
⇒ f ( xi − 2 ) ≈ f ( xi ) − f ′( xi )( 2h) + ( 2h) 2 − ( 2h ) 3 + ( 2h ) 4 + O (h 5 ) (v )
2! 3! 4!

Eqn. (iv)-Eqn. (v):


16 f ′′′( xi ) 3
f ( xi + 2 ) − f ( xi − 2 ) = 4 f ′( xi )h + h + O(h 5 ) (vi )
3!

ME 261: Numerical Analysis 5

Central Finite Difference Formula cont…


f ′( xi ) = ? h

→x
i−2 i −1 i i +1 i + 2 (1 − D )
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central difference formulation

2 f ′′′( xi ) 3
f ( xi +1 ) − f ( xi −1 ) = 2 f ′( xi )h + h + O(h5 ) (iii )
3!
16 f ′′′( xi ) 3
f ( xi + 2 ) − f ( xi − 2 ) = 4 f ′( xi )h + h + O(h5 ) (vi )
3!

Now, Eqn. (vi) - Eqn. (iii)×8:

f ( xi + 2 ) − f ( xi − 2 ) − 8 f ( xi +1 ) + 8 f ( xi −1 ) = −12 f ′( xi ) h + O(h 5 )

− f ( xi + 2 ) + 8 f ( xi +1 ) − 8 f ( xi −1 ) + f ( xi − 2 )
⇒ f ′( xi ) = + O (h 4 )
12 h

O(h4) using 4 points: xi+2 , xi+1 , xi-2 and xi-1

4th order, O( h 4 ) approximation of f ′( xi ) using central difference formula

ME 261: Numerical Analysis 6

3
Central Finite Difference Formula cont…
Second derivative: O(h2) f ′( xi ) = ? h

d2y →x
f ′′( xi ) / : i + 2 (1 − D )
dx 2 i−2 i −1 i i +1
x = xi
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central Finite Difference Formula: Central difference formulation

f ( xi +1 ) can be approximat ed using Taylor series expansion -


f ′′( xi ) 2 f ′′′( xi ) 3 f n ( xi ) n
f ( xi +1 ) = f ( xi ) + f ′( xi )h + h + h + ... ... ... + h + O ( h n +1 )
2! 3! n!
f ′′( xi ) 2 f ′′′( xi ) 3
⇒ f ( xi +1 ) ≈ f ( xi ) + f ′( xi ) h + h + h + O(h 4 ) (i)
2! 3!

Similarly , f ( xi −1 ) can be approximat ed using Taylor series expansion -


f ′′( xi ) 2 f ′′′( xi ) 3 f n ( xi ) n
f ( xi −1 ) = f ( xi ) − f ′( xi )h + h − h + ... ... ... + h + O ( h n +1 )
2! 3! n!
f ′′( xi ) 2 f ′′′( xi ) 3
⇒ f ( xi −1 ) ≈ f ( xi ) − f ′( xi )h + h − h + O (h 4 ) (ii )
2! 3!

ME 261: Numerical Analysis 7

Central Finite Difference Formula cont…


f ′( xi ) = ? h

→x
i−2 i −1 i i +1 i + 2 (1 − D )
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central difference formulation
Add Eqn. (i) and Eqn. (ii)

f ′′( xi ) 2
f ( xi +1 ) + f ( xi −1 ) = 2 f ( xi ) + 2 h + O (h 4 )
2!

f ( xi +1 ) − 2 f ( xi ) + f ( xi −1 )
⇒ f ′′( xi ) = + O (h 2 )
h2

d2y f ( xi +1 ) − 2 f ( xi ) + f ( xi −1 )
⇒ = + O (h 2 )
dx 2 x = xi
h2

O(h2) using 3 points: xi+1 , xi and xi-1

2nd order, O ( h 2 ) approximat ion of f ′′( xi ) using central difference formula

ME 261: Numerical Analysis 8

4
Central Finite Difference Formula cont…
Third derivative: O(h2) f ′( xi ) = ? h

d3y →x
f ′′′( xi ) / : i −1 i i +1 i + 2 (1 − D )
dx 3 i−2
x = xi
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central Finite Difference Formula: Central difference formulation

f ( xi +1 ) can be approximat ed using Taylor series expansion -


f ′′( xi ) 2 f ′′′( xi ) 3 f IV ( xi ) 4 f n ( xi ) n
f ( xi +1 ) = f ( xi ) + f ′( xi )h + h + h + h + ... ... ... + h + O ( h n +1 )
2! 3! 4! n!
f ′′( xi ) 2 f ′′′( xi ) 3 f IV ( xi ) 4
⇒ f ( xi +1 ) ≈ f ( xi ) + f ′( xi ) h + h + h + h + O(h 5 ) (i )
2! 3! 4!
Similarly, f ( xi −1 ) can be approximat ed using Taylor series expansion -
f ′′( xi ) 2 f ′′′( xi ) 3 f IV ( xi ) 4 f n ( xi ) n
f ( xi −1 ) = f ( xi ) − f ′( xi )h + h − h + h − ... ... ... + h + O ( h n +1 )
2! 3! 4! n!
f ′′( xi ) 2 f ′′′( xi ) 3 f IV ( xi ) 4
⇒ f ( xi −1 ) ≈ f ( xi ) − f ′( xi )h + h − h + h + O (h 5 ) (ii )
2! 3! 4!
Eqn. (i)-Eqn. (ii):
2 f ′′′( xi ) 3
f ( xi +1 ) − f ( xi −1 ) = 2 f ′( xi )h + h + O( h 5 ) (iii )
3!

ME 261: Numerical Analysis 9

Central Finite Difference Formula cont…


f ′( xi ) = ? h

→x
i−2 i −1 i i +1 i + 2 (1 − D )
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central difference formulation

f ( xi + 2 ) can be approximated using Taylor series expansion -


f ′′( xi ) f ′′′( xi ) f IV ( xi ) f n ( xi )
f ( xi + 2 ) = f ( xi ) + f ′( xi )(2h) + ( 2 h) 2 + (2 h ) 3 + (2h) 4 + ... ... ... + (2h) n + O (h n +1 )
2! 3! 4! n!
f ′′( xi ) f ′′′( xi ) f IV ( xi )
⇒ f ( xi + 2 ) ≈ f ( xi ) + f ′( xi )( 2h) + ( 2h ) 2 + ( 2h ) 3 + ( 2 h) 4 + O(h 5 ) (iv)
2! 3! 4!

Similarly, f ( xi − 2 ) can be approximated using Taylor series expansion -


f ′′( xi ) f ′′′( xi ) f IV ( xi ) f n ( xi )
f ( xi − 2 ) = f ( xi ) − f ′( xi )(2h) + ( 2 h) 2 − ( 2h) 3 + ( 2h) 4 − ... ... ... + ( 2h ) n + O ( h n + 1 )
2! 3! 4! n!
f ′′( xi ) f ′′′( xi ) f IV ( xi )
⇒ f ( xi − 2 ) ≈ f ( xi ) − f ′( xi )( 2h) + ( 2h) 2 − ( 2h ) 3 + ( 2h ) 4 + O (h 5 ) (v )
2! 3! 4!

Eqn. (iv)-Eqn. (v):


16 f ′′′( xi ) 3
f ( xi + 2 ) − f ( xi − 2 ) = 4 f ′( xi )h + h + O(h 5 ) (vi )
3!

ME 261: Numerical Analysis 10

5
Central Finite Difference Formula cont…
f ′( xi ) = ? h

→x
i−2 i −1 i i +1 i + 2 (1 − D )
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central difference formulation

2 f ′′′( xi ) 3
f ( xi +1 ) − f ( xi −1 ) = 2 f ′( xi )h + h + O( h 5 ) (iii )
3!
16 f ′′′( xi ) 3
f ( xi + 2 ) − f ( xi − 2 ) = 4 f ′( xi )h + h + O(h5 ) (vi )
3!

Now, Eqn. (vi) - Eqn. (iii)×2: (to remove f/(xi))


 16 4 
f ( xi + 2 ) − f ( xi − 2 ) − 2 f ( xi +1 ) + 2 f ( xi −1 ) =  −  f ′′′( xi )h 3 + O(h5 )
 3! 3! 

f ( xi + 2 ) − 2 f ( xi +1 ) + 2 f ( xi −1 ) − f ( xi − 2 )
⇒ f ′′′( xi ) = + O(h 2 )
2h 3

O(h2) using 4 points: xi+2 , xi+1 , xi-2 and xi-1

2nd order, O (h 2 ) approximation of f ′′′( xi ) using central difference formula

ME 261: Numerical Analysis 11

Central Finite Difference Formula cont…


Fourth derivative: O(h2) f ′( xi ) = ? h

d4y →x
f IV ( xi ) / : i + 2 (1 − D )
dx 4 i−2 i −1 i i +1
x = xi
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central Finite Difference Formula: Central difference formulation

f ( xi + 2 ) can be approximat ed using Taylor series expansion -


f ′′( xi ) f ′′′( xi ) f IV ( xi ) f V ( xi )
f ( xi + 2 ) ≈ f ( xi ) + f ′( xi )(2h) + ( 2h) 2 + ( 2 h) 3 + ( 2 h) 4 + ( 2h ) 5 + O( h 6 ) (i )
2! 3! 4! 5!
Similarly, f ( xi − 2 ) can be approximat ed using Taylor series expansion -
f ′′( xi ) f ′′′( xi ) f IV ( xi ) f V ( xi )
⇒ f ( xi − 2 ) ≈ f ( xi ) − f ′( xi )(2h) + ( 2h) 2 − ( 2 h) 3 + ( 2h) 4 − ( 2 h) 5 + O (h 6 ) (ii )
2! 3! 4! 5!

Eqn. (i)+Eqn.(ii):

f ′′( xi ) f IV ( xi )
f ( xi + 2 ) + f ( xi − 2 ) = 2 f ( xi ) + 2 ( 2 h) 2 + 2 ( 2h) 4 + O (h 6 ) (iii )
2! 4!

ME 261: Numerical Analysis 12

6
Central Finite Difference Formula cont…
f ′( xi ) = ? h

→x
i−2 i −1 i i +1 i + 2 (1 − D )
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central difference formulation

f ( xi +1 ) can be approximat ed using Taylor series expansion -


f ′′( xi ) 2 f ′′′( xi ) 3 f IV ( xi ) 4 f V ( xi ) 5
f ( xi +1 ) ≈ f ( xi ) + f ′( xi ) h + h + h + h + h + O( h 6 ) (iv )
2! 3! 4! 5!

Similarly, f ( xi +1 ) can be approximat ed using Taylor series expansion -


f ′′( xi ) 2 f ′′′( xi ) 3 f IV ( xi ) 4 f V ( xi ) 5
f ( xi −1 ) ≈ f ( xi ) − f ′( xi )h + h − h + h − h + O( h 6 ) (v)
2! 3! 4! 5!

Eqn. (iv)+Eqn.(v):

f ′′( xi ) 2 f IV ( xi ) 4
f ( xi +1 ) + f ( xi −1 ) = 2 f ( xi ) + 2 h +2 h + O(h 6 ) (vi )
2! 4!

ME 261: Numerical Analysis 13

Central Finite Difference Formula cont…


f ′( xi ) = ? h

→x
i−2 i −1 i i +1 i + 2 (1 − D )
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central difference formulation
We have two equations: Eqn.(iii) & Eqn.(vi)

f ′′( xi ) f IV ( xi )
f ( xi + 2 ) + f ( xi − 2 ) = 2 f ( xi ) + 2 ( 2h ) 2 + 2 ( 2 h) 4 + O (h 6 ) (iii )
2! 4!
4
⇒ 4 f ′′( xi )h 2 + f IV
( xi ) h 4 = f ( xi + 2 ) − 2 f ( xi ) + f ( xi − 2 ) (vii )
3

f ′′( xi ) 2 f IV ( xi ) 4
f ( xi +1 ) + f ( xi −1 ) = 2 f ( xi ) + 2 h +2 h + O (h 6 ) (vi )
2! 4!
1
⇒ f ′′( xi )h 2 + f IV
( xi ) h 4 = f ( xi +1 ) − 2 f ( xi ) + f ( xi −1 ) (viii )
12

ME 261: Numerical Analysis 14

7
Central Finite Difference Formula cont…
f ′( xi ) = ? h

→x
i−2 i −1 i i +1 i + 2 (1 − D )
f ( xi − 2 ) f ( xi −1 ) f ( xi ) f ( xi +1 ) f ( xi + 2 )
Central difference formulation
Eqn.(vii) - Eqn.(viii)×4 results:

4 IV
4 f ′′( xi )h 2 + f ( xi )h 4 = f ( xi + 2 ) − 2 f ( xi ) + f ( xi − 2 ) (vii)
3
1 IV
f ′′( xi ) h 2 + f ( xi ) h 4 = f ( xi +1 ) − 2 f ( xi ) + f ( xi −1 ) (viii ) × 4
12

f ( xi + 2 ) − 4 f ( xi +1 ) + 6 f ( xi ) − 4 f ( xi −1 ) + f ( xi − 2 )
f IV
( xi ) = + O(h 2 )
h4

d4y f ( xi + 2 ) − 4 f ( xi +1 ) + 6 f ( xi ) − 4 f ( xi −1 ) + f ( xi − 2 )
= + O(h 2 )
dx 4 x = xi
h4

O(h2) using 5 points: xi+2 , xi+1 , xi, xi-2 and xi-1

2nd order, O( h 2 ) approximat ion of f IV ( xi ) using central difference formula

ME 261: Numerical Analysis 15

Numerical Differentiation

In all the finite difference formulas, the sum of all the coefficients of the function values,
f(xi) appearing in the numerator can be seen to be zero. Physically this implies that the
derivative becomes zero if f(x) is a constant.

The accuracy of the computed derivatives can be improved either by using a smaller
step size (h) or by using a higher accuracy formula.

ME 261: Numerical Analysis 16

8
Problem
For symmetric stress distribution of a circular body, the stress function Φ is governed by
the following DEQ:
d 4φ 2 d 3φ 1 d 2φ 1 dφ
+ − + =0
dr 4 r dr 3 r 2 dr 2 r 3 dr

Derive the corresponding central-difference algebraic equation with an error of O(h2)


and show the corresponding finite-difference stencil.

d 4φ φ (ri + 2 ) − 4φ (ri +1 ) + 6φ (ri ) − 4φ (ri −1 ) + φ (ri − 2 )


= + O(h 2 )
dr 4 r = ri
h4

3
d φ φ (ri + 2 ) − 2φ (ri +1 ) + 2φ (ri −1 ) − φ (ri − 2 )
= + O( h 2 )
dr 3 r = ri
2h 3

d 2φ φ (ri +1 ) − 2φ (ri ) + φ (ri −1 )


= + O(h 2 )
dr 2 r = ri
h2

dφ φ (ri +1 ) − φ (ri −1 )
= + O (h 2 )
dr r = ri 2h

ME 261: Numerical Analysis 17

You might also like