0% found this document useful (0 votes)
118 views

Numerical Differentiation

Uploaded by

Mahfuja Mim
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)
118 views

Numerical Differentiation

Uploaded by

Mahfuja Mim
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/ 47

ME 261: Numerical Analysis

Priom Das
Lecturer
Department of Mechanical Engineering, BUET

Term: January 2023

Lecture: Numerical Differentiation

ME 261: Numerical Analysis


ME 261 .. Numerical Analysis

Lecture # 01

Numerical Differentiation
ME 261 .. Introduction to Differentiation

Definition: Example:

f f ( x + x ) − f ( x )
= lim
x x → 0 x
f ( x + h) − f ( x)
= lim
h →0 h
y
= lim
x → 0 x
ME 261 .. Application of Differentiation
ME 261 .. Application of Differentiation
ME 261 .. Application of Differentiation
ME 261 .. Application of Differentiation
ME 261 .. Differentiation vs Integration
ME 261 .. Application of Numerical Differentiation

In Business World, one of the important


applications of derivatives is when the data
has been charted on graph or data table such
as excel. Once it has been input, the data can
be graphed and with the applications of
derivatives, one can estimate the profit and
loss point for certain ventures.
ME 261 .. Application of Numerical Differentiation

In an Automobile, there is always an


Odometer and a Speedometer. These two
gauges work in tandem and allow driver to
determine his speed and his distance that
he has traveled. Electronic versions of
these gauges simply use derivatives to
transform the data sent to electronic
motherboard from the tires to miles per
hour (mph) and distance (km).

Police officers use radar guns by taking


advantages of the easy use of derivatives.
When a radar gun is pointed and fired at
one’s car in highway, the gun can
determine the time and distance at which
the radar was able to hit a certain section
of the vehicle. With the use of derivative, it
can calculate the speed at which the car
was going and report the distance that the
car was from the radar gun.
ME 261 .. Numerical Differentiation

Finite difference approximations of derivatives are derived from


the approximations of Taylor’s series expansion.
i−2 i−1 i i+1 i+2
x
xi−1 f’(xi) xi xi+1 Independent variable: xi = x0 + ih,
Dependent variable: fi = f(xi) = f(x0 + ih),
h i = 0, 1, 2, ….., n

• y = f(x), yi+1 = y(xi+1) = y(x+h) = f(xi+1) = f(x+h)


• Using Taylor’s series expansion of f(xi+1) = f(x+h),
h2 h3 h 4 iv
f ( xi +1 )  f ( xi ) + hf  ( xi ) + f  ( xi ) + f  ( xi ) + f ( xi ) + O ( h 5 ) (1)
2! 3! 4!

• Using Taylor’s series expansion of f(xi−1) = f(x−h),


h2 h3 h 4 iv
f ( xi −1 )  f ( xi ) − hf  ( xi ) + f  ( xi ) − f  ( xi ) + f ( xi ) − O ( h 5 ) (2)
2! 3! 4!
ME 261 .. Numerical Differentiation

Finite difference approximations of derivatives are derived from


the approximations of Taylor’s series expansion.
i−2 i−1 i i+1 i+2
x
xi−1 f’(xi) xi xi+1 Independent variable: xi = x0 + ih,
Dependent variable: fi = f(xi) = f(x0 + ih),
h i = 0, 1, 2, ….., n

• y = f(x), yi+2 = y(xi+2) = y(x+2h) = f(xi+2) = f(x+2h)


• Using Taylor’s series expansion of f(xi+2) = f(x+2h),
( 2h ) ( 2h )
2 3

f ( xi + 2 )  f ( xi ) + ( 2h ) f  ( xi ) + f  ( xi ) + f  ( xi ) + O ( h 4 ) (3)
2! 3!
• Using Taylor’s series expansion of f(xi−2) = f(x−2h),
( 2h ) ( 2h )
2 3

f ( xi − 2 )  f ( xi ) − ( 2h ) f  ( xi ) + f  ( xi ) − f  ( xi ) + O ( h 4 ) (4)
2! 3!
ME 261 .. Numerical Differentiation

Finite difference approximations of derivatives are derived from


the approximations of Taylor’s series expansion.
i−3 i−2 i−1 i i+1 i+2 i+3
x
xi−1 f’(xi) xi xi+1 Independent variable: xi = x0 + ih,
Dependent variable: fi = f(xi) = f(x0 + ih),
h i = 0, 1, 2, ….., n

• y = f(x), yi+3 = y(xi+3) = y(x+3h) = f(xi+3) = f(x+3h)


• Using Taylor’s series expansion of f(xi+3) = f(x+3h),
( 3h ) ( 3h )
2 3

f ( xi +3 )  f ( xi ) + ( 3h ) f  ( xi ) + f  ( xi ) + f  ( xi ) + O ( h 4 ) (5)
2! 3!
• Using Taylor’s series expansion of f(xi−3) = f(x−3h),
( 3h ) ( 3h )
2 3

f ( xi −3 )  f ( xi ) − ( 3h ) f  ( xi ) + f  ( xi ) − f  ( xi ) + O ( h 4 ) (6)
2! 3!
ME 261 .. Numerical Differentiation

Taylor’s series expansion:

h2 h3 h 4 iv
f ( xi +1 )  f ( xi ) + hf  ( xi ) + f  ( xi ) + f  ( xi ) + f ( xi ) + O ( h 5 ) (1)
2! 3! 4!
h2 h3 h 4 iv
f ( xi −1 )  f ( xi ) − hf  ( xi ) + f  ( xi ) − f  ( xi ) + f ( xi ) − O ( h 5 ) (2)
2! 3! 4!
( 2h ) ( 2h ) ( 2h )
2 3 4

f ( xi + 2 )  f ( xi ) + ( 2h ) f  ( xi ) + f  ( xi ) + f  ( xi ) + f iv ( xi ) + O ( h 5 ) (3)
2! 3! 4!

( 2h ) ( 2h ) ( 2h )
2 3 4

f ( xi − 2 )  f ( xi ) − ( 2h ) f  ( xi ) + f  ( xi ) − f  ( xi ) + f iv ( xi ) − O ( h 5 ) (4)
2! 3! 4!

( 3h ) ( 3h ) ( 3h )
2 3 4

f ( xi +3 )  f ( xi ) + ( 3h ) f  ( xi ) + f  ( xi ) + f  ( xi ) + f iv ( xi ) + O ( h 5 ) (5)
2! 3! 4!
( 3h ) ( 3h ) ( 3h )
2 3 4

f ( xi −3 )  f ( xi ) − ( 3h ) f  ( xi ) + f  ( xi ) − f  ( xi ) + f iv ( xi ) − O ( h 5 ) (6)
2! 3! 4!
ME 261 .. Numerical Differentiation

Techniques:

• The solution of the differential equation can numerically be


computed using Finite Difference Method (FDM). In FDM, the
derivatives of an original differential equation can be
approximated using the finite difference approximation (via
Taylor series).

• Numerical differentiation is the procedure by which the


derivatives of a function are computed as a series of numbers
of discrete points in the region of interest.
ME 261 .. Numerical Differentiation

Q: With necessary diagrams, describe Forward Difference, Backward


Difference and Central Difference approach of Numerical Differentiation.
Explain their applicability and relative advantages/disadvantages in context to
practical problems.
• There are three approaches:
1. Forward difference scheme (FDS) or formula (FDF)
2. Backward difference scheme (BDS) or formula (BDF)
3. Central difference scheme (CDS) or formula (CDF)
ME 261 .. Numerical Differentiation
(First Derivative)
Finite difference approximations of derivatives are derived from
the approximations of Taylor’s series expansion.
i−2 i−1 i i+1 i+2
x
xi−1 f’(xi) xi xi+1
h
• From (1) f ( xi +1 ) − f ( xi ) h
f  ( xi ) = − f  ( xi ) −
h 2

f ( xi +1 ) − f ( xi )
Thus, f  ( xi ) = + O (h) Error
h

This is called Forward Difference Scheme (FDS) / Approximation for f’(x)


[2 points formula]
ME 261 .. Numerical Differentiation
(First Derivative)
Finite difference approximations of derivatives are derived from
the approximations of Taylor’s series expansion.
i−2 i−1 i i+1 i+2
x
xi−1 f’(xi) xi xi+1
h
• From (2) f ( xi ) − f ( xi −1 ) h
f  ( xi ) = + f  ( xi ) −
h 2

f ( xi ) − f ( xi −1 )
Thus, f  ( xi ) = + O (h) Error
h

This is called Backward Difference Scheme (BDS) / Approximation for f’(x)


[2 points formula]
ME 261 .. Numerical Differentiation
(First Derivative)
Finite difference approximations of derivatives are derived from
the approximations of Taylor’s series expansion.
i−2 i−1 i i+1 i+2
x
xi−1 f’(xi) xi xi+1
h
h3
• From (1) − (2) f ( xi +1 ) − f ( xi −1 ) = 2hf  ( xi ) + 2 f  ( xi ) + (7)
3!

f ( xi +1 ) − f ( xi −1 )
Thus, f  ( xi ) = + O ( h2 ) Error
2h

This is called Central Difference Scheme (CDS) / Approximation for f’(x)


[3 points formula]
ME 261 .. Numerical Differentiation
(First Derivative)
Comparison of FDS, BDS and CDS

➢ Truncation error of O(h2) < Truncation error of O(h).


➢ CDS is superior to FDS or BDS even if the order of error for all
schemes is the same.
➢ CDS cannot be applied in every case, since some practical
problems may not include the function values at previous
points. For example, time dependent phenomena (e.g., motion
of a projectile starts from t = 0. If the displacement of a
projectile is given to determine the velocity, CDS cannot be
used as data before t = 0 are not available.
➢ Truncation error can be reduced by adding more terms of
Taylor series in the formula.
ME 261 .. Numerical Differentiation
(First Derivative)
Comparison of FDS, BDS and CDS
ME 261 .. Numerical Differentiation
(First Derivative)
Finite difference approximations of derivatives are derived from
the approximations of Taylor’s series expansion.
i−2 i−1 i i+1 i+2
x
xi−1 f’(xi) xi xi+1
h
• From 4×(1) − (3)
h3
4 f ( xi +1 ) − f ( xi + 2 ) = 3 f ( xi ) + 2hf  ( xi ) − 4 f  ( xi ) + O ( h 4 ) (8)
3!
−3 f ( xi ) + 4 f ( xi +1 ) − f ( xi + 2 )
Thus, f  ( xi ) = + O ( h2 ) Error
2h

This is called Forward Difference Scheme (FDS) / Approximation for f’(x)


[3 points formula]
ME 261 .. Numerical Differentiation
(First Derivative)
Finite difference approximations of derivatives are derived from
the approximations of Taylor’s series expansion.
i−2 i−1 i i+1 i+2
x
xi−1 f’(xi) xi xi+1
h
• From 4×(2) − (4)
h3
4 f ( xi −1 ) − f ( xi − 2 ) = 3 f ( xi ) − 2hf  ( xi ) + 4 f  ( xi ) + O ( h 4 ) (9)
3!
3 f ( xi ) − 4 f ( xi −1 ) + f ( xi − 2 )
Thus, f  ( xi ) = + O ( h2 ) Error
2h
This is called Backward Difference Scheme (BDS) / Approximation for f’(x)
[3 points formula]
ME 261 .. Numerical Differentiation
(First Derivative)
i−2 i−1 i i+1 i+2 i+3
x
xi−1 f’(xi) xi xi+1
h
• From 9×(1) − (5)
h3
9 f ( xi +1 ) − f ( xi +3 ) = 8 f ( xi ) + 6hf  ( xi ) − 18 f  ( xi ) + O ( h 4 ) (10)
3!
• From 9×(8) − 2× (10)
18 f ( xi +1 ) − 9 f ( xi + 2 ) + 2 f ( xi +3 ) = 11 f ( xi ) + 6hf  ( xi ) + O ( h 4 )

Thus, −11 f ( xi ) + 18 f ( xi +1 ) − 9 f ( xi + 2 ) + 2 f ( xi +3 )
f  ( xi ) = + O ( h3 ) Error
6h
This is called Forward Difference Scheme (FDS) / Approximation for f’(x)
[4 points formula]
ME 261 .. Numerical Differentiation
(First Derivative)
i−3 i−2 i−1 i i+1 i+2 i+3
x
xi−1 f’(xi) xi xi+1
h
• From 9×(2) − (6)
h3
9 f ( xi −1 ) − f ( xi −3 ) = 8 f ( xi ) − 6hf  ( xi ) + 18 f  ( xi ) + O ( h 4 ) (11)
3!
• From 9×(9) − 2× (11)
18 f ( xi −1 ) − 9 f ( xi − 2 ) + 2 f ( xi −3 ) = 11 f ( xi ) − 6hf  ( xi ) + O ( h 4 )

Thus, 11 f ( xi ) − 18 f ( xi −1 ) + 9 f ( xi − 2 ) − 2 f ( xi −3 )
f  ( xi ) = + O ( h3 ) Error
6h
This is called Backward Difference Scheme (BDS) / Approximation for f’(x)
[4 points formula]
ME 261 .. Numerical Differentiation
(First Derivative)
i−3 i−2 i−1 i i+1 i+2 i+3
x
xi−1 f’(xi) xi xi+1
h h3
• From (3) − (4) f ( xi+2 ) − f ( xi −2 ) = 4 hf  ( xi ) + 16 f  ( xi ) + O (
3!
h 5
) (12)
• From (12) − 8 ×(7)
f ( xi + 2 ) − f ( xi − 2 ) − 8 f ( xi +1 ) + 8 f ( xi −1 ) = −12hf  ( xi ) + O ( h 5 )

f ( xi − 2 ) − 8 f ( xi −1 ) + 8 f ( xi +1 ) − f ( xi + 2 )
Thus, f  ( xi ) = + O ( h4 ) Error
12h

This is called Central Difference Scheme (CDS) / Approximation for f’(x)


[5 points formula]
ME 261 .. Numerical Differentiation
(Second Derivative)
Finite difference approximations of derivatives are derived from
the approximations of Taylor’s series expansion.
i−2 i−1 i i+1 i+2
x
xi−1 f’(xi) xi xi+1
h
• From 2×(1) − (3)
h2 h3
2 f ( xi +1 ) − f ( xi + 2 ) = f ( xi ) − 2 f  ( xi ) − 6 f  ( xi ) + O ( h 4 ) (13)
2! 3!
f ( xi ) − 2 f ( xi +1 ) + f ( xi + 2 )
Thus, f  ( xi ) = 2
+ O (h) Error
h

This is called Forward Difference Scheme (FDS) / Approximation for f”(x)


[3 points formula]
ME 261 .. Numerical Differentiation
(Second Derivative)
Finite difference approximations of derivatives are derived from
the approximations of Taylor’s series expansion.
i−2 i−1 i i+1 i+2
x
xi−1 f’(xi) xi xi+1
h
• From 2×(2) − (4)
h2 h3
2 f ( xi −1 ) − f ( xi − 2 ) = f ( xi ) − 2 f  ( xi ) + 6 f  ( xi ) + O ( h 4 ) (14)
2! 3!
f ( xi − 2 ) − 2 f ( xi −1 ) + f ( xi )
Thus, f  ( xi ) = 2
+ O (h) Error
h

This is called Backward Difference Scheme (BDS) / Approximation for f”(x)


[3 points formula]
ME 261 .. Numerical Differentiation
(Second Derivative)
Finite difference approximations of derivatives are derived from
the approximations of Taylor’s series expansion.
i−2 i−1 i i+1 i+2
x
xi−1 f’(xi) xi xi+1
h
• From (1) + (2)
h2 h 4 iv
f ( xi +1 ) + f ( xi −1 ) = 2 f ( xi ) + 2 f  ( xi ) + 2 f ( xi ) + O ( h 6 ) (15)
2! 4!
f ( xi −1 ) − 2 f ( xi ) + f ( xi +1 )
Thus, f  ( xi ) = 2
+ O ( h2 ) Error
h

This is called Central Difference Scheme (CDS) / Approximation for f”(x)


[3 points formula]
ME 261 .. Numerical Differentiation
(Second Derivative)
i−2 i−1 i i+1 i+2 i+3
x
xi−1 f’(xi) xi xi+1
h
• From 3×(1) − (5)
h2 h3
3 f ( xi +1 ) − f ( xi +3 ) = 2 f ( xi ) − 6 f  ( xi ) − 24 f  ( xi ) + O ( h 4 ) (16)
2! 3!
• From 4×(13) − (16)
h2
5 f ( xi +1 ) − 4 f ( xi + 2 ) + f ( xi +3 ) = 2 f ( xi ) − 2 f  ( xi ) + O ( h 4 )
2!
Thus, 2 f ( xi ) − 5 f ( xi +1 ) + 4 f ( xi + 2 ) − f ( xi +3 )
f  ( xi ) = + O ( h2 ) Error
h2
This is called Forward Difference Scheme (FDS) / Approximation for f’’(x)
[4 points formula]
ME 261 .. Numerical Differentiation
(Second Derivative)
i−3 i−2 i−1 i i+1 i+2 i+3
x
xi−1 f’(xi) xi xi+1
h
• From 3×(2) − (6)
h2 h3
3 f ( xi −1 ) − f ( xi −3 ) = 2 f ( xi ) − 6 f  ( xi ) + 24 f  ( xi ) + O ( h 4 ) (17)
2! 3!
• From 4×(14) − (17)
h2
5 f ( xi −1 ) − 4 f ( xi − 2 ) + f ( xi −3 ) = 2 f ( xi ) − 2 f  ( xi ) + O ( h 4 )
2!
Thus, 2 f ( xi ) − 5 f ( xi −1 ) + 4 f ( xi − 2 ) − f ( xi −3 )
f  ( xi ) = + O ( h2 ) Error
h2
This is called Backward Difference Scheme (BDS) / Approximation for f’’(x)
[4 points formula]
ME 261 .. Numerical Differentiation
(Second Derivative)
i−3 i−2 i−1 i i+1 i+2 i+3
x
xi−1 f’(xi) xi xi+1
h
• From (3) + (4)
h2 h 4 iv
f ( xi + 2 ) + f ( xi − 2 ) = 2 f ( xi ) + 8 f  ( xi ) + 32 f ( xi ) + O ( h 6 ) (18)
2! 4!
• From 16×(15) − (18)
h2
16 f ( xi +1 ) + 16 f ( xi −1 ) − f ( xi + 2 ) − f ( xi − 2 ) = 30 f ( xi ) + 24 f  ( xi ) + O ( h 6 )
2!
Thus, − f ( xi − 2 ) + 16 f ( xi −1 ) − 30 f ( xi ) + 16 f ( xi +1 ) − f ( xi + 2 )
f  ( xi ) = + O ( h4 ) Error
12h 2
This is called Central Difference Scheme (CDS) / Approximation for f’’(x)
[5 points formula]
ME 261 .. Numerical Differentiation

Summary of Derivation of First Derivative


Scheme O(h) O(h2) O(h3) O(h4)
FDS (1) 4 × (1) − (3) => (8) 9 × (1) − (5) => (10) -
9 × (8) − 2 × (10)
BDS (2) 4 × (2) − (4) => (9) 9 × (2) − (6) => (11) -
9 × (9) − 2 × (11)
CDS - (1) − (2) => (7) - (3) − (4) => (12)
(12) − 8 × (7)

Summary of Derivation of Second Derivative


Scheme O(h) O(h2) O(h4)
FDS 2 × (1) − (3) => (13) 3 × (1) − (5) => (16) -
4 × (13) − (16)
BDS 2 × (2) − (4) => (14) 3 × (2) − (6) => (17) -
4 × (14) − (17)
CDS - (1) + (2) => (15) (3) + (4) => (18)
16 × (15) − (18)
ME 261 .. Numerical Differentiation

Home Task / Class Practice

1. Derive the finite difference formula of third derivative with an


error of O(h2) using central finite difference approximation.

2. Derive the finite difference formula of fourth derivative with an


error of O(h2) using central finite difference approximation.

Important Note
1. Minimum number of terms required for nth derivative = n + 1.
2. In all the finite difference formulas, the sum of all the
coefficients of the function values, f(xi) in the numerator can be
observed to be zero. Physically this implies that the derivatives
becomes zero if f(x) is a constant.
Numerical Differentiation
ME 261 ..
(Third Derivative)
Question 1: Derive the finite difference formula of third derivative
with an error of O(h2) using central finite difference approximation.
i−2 i−1 i i+1 i+2
x
xi−1 f’(xi) xi xi+1 Independent variable: xi = x0 + ih,
Dependent variable: fi = f(xi) = f(x0 + ih),
h i = 0, 1, 2, ….., n

• y = f(x), yi+1 = y(xi+1) = y(x+h) = f(xi+1) = f(x+h)


• Using Taylor’s series expansion of f(xi+1) = f(x+h),
h2 h3 h 4 iv
f ( xi +1 )  f ( xi ) + hf  ( xi ) + f  ( xi ) + f  ( xi ) + f ( xi ) + O ( h 5 ) (1)
2! 3! 4!

• Using Taylor’s series expansion of f(xi−1) = f(x−h),


h2 h3 h 4 iv
f ( xi −1 )  f ( xi ) − hf  ( xi ) + f  ( xi ) − f  ( xi ) + f ( xi ) − O ( h 5 ) (2)
2! 3! 4!
Numerical Differentiation
ME 261 ..
(Third Derivative)
From (1) − (2) From (1) + (2)
f ( xi +1 ) − f ( xi −1 ) f ( xi −1 ) − 2 f ( xi ) + f ( xi +1 )
f  ( xi ) = + O (h 2
) f  ( xi ) = + O ( h2 )
2h h2
Thus, d
f  ( xi ) =  f  ( xi ) 
dx
d  f ( xi −1 ) − 2 f ( xi ) + f ( xi +1 ) 
=  
dx  h2 
1
=  f  ( xi −1 ) − 2 f  ( xi ) + f  ( xi +1 ) 
2 
h
1  f ( xi ) − f ( xi − 2 )  f ( xi +1 ) − f ( xi −1 )  f ( xi + 2 ) − f ( xi ) 
=  − 2 + 
h 2  2h  2 h  2 h 
1
=  f ( xi ) − f ( xi − 2 ) − 2 f ( xi +1 ) + 2 f ( xi −1 ) + f ( xi + 2 ) − f ( xi ) 
2h 3 
− f ( xi − 2 ) + 2 f ( xi −1 ) − 2 f ( xi +1 ) + f ( xi + 2 )
f  ( xi ) =
2h 3
+ O ( h 2
) Error
Numerical Differentiation
ME 261 ..
(Fourth Derivative)
Question 2: Derive the finite difference formula of fourth derivative
with an error of O(h2) using central finite difference approximation.
i−2 i−1 i i+1 i+2
x
xi−1 f’(xi) xi xi+1 Independent variable: xi = x0 + ih,
Dependent variable: fi = f(xi) = f(x0 + ih),
h i = 0, 1, 2, ….., n

• y = f(x), yi+1 = y(xi+1) = y(x+h) = f(xi+1) = f(x+h)


• Using Taylor’s series expansion of f(xi+1) = f(x+h),
h2 h3 h 4 iv
f ( xi +1 )  f ( xi ) + hf  ( xi ) + f  ( xi ) + f  ( xi ) + f ( xi ) + O ( h 5 ) (1)
2! 3! 4!

• Using Taylor’s series expansion of f(xi−1) = f(x−h),


h2 h3 h 4 iv
f ( xi −1 )  f ( xi ) − hf  ( xi ) + f  ( xi ) − f  ( xi ) + f ( xi ) − O ( h 5 ) (2)
2! 3! 4!
Numerical Differentiation
ME 261 ..
(Fourth Derivative)
• From (1) + (2)
h2 h 4 iv
f ( xi +1 ) + f ( xi −1 ) = 2 f ( xi ) + 2 f  ( xi ) + 2 f ( xi ) + O ( h 6 )
2! 4!
f ( xi −1 ) − 2 f ( xi ) + f ( xi +1 )
Thus, f ( xi ) =

h 2
+ O ( h 2
)
d2
f ( xi ) = 2  f  ( xi ) 
iv

dx
d 2  f ( xi −1 ) − 2 f ( xi ) + f ( xi +1 ) 
= 2 
dx  h2 
1
=  f  ( xi −1 ) − 2 f  ( xi ) + f  ( xi +1 ) 
h2 
1  f ( xi − 2 ) − 2 f ( xi −1 ) + f ( xi )  f ( xi −1 ) − 2 f ( xi ) + f ( xi +1 )  f ( xi ) − 2 f ( xi +1 ) + f ( xi + 2 ) 
= 2 − 2 + 
h  h2  h 2
 h 2

1
= 4  f ( xi − 2 ) − 2 f ( xi −1 ) + f ( xi ) − 2 f ( xi −1 ) + 4 f ( xi ) − 2 f ( xi +1 ) + f ( xi ) − 2 f ( xi +1 ) + f ( xi + 2 ) 
h
f ( xi − 2 ) − 4 f ( xi −1 ) + 6 f ( xi ) − 4 f ( xi +1 ) + f ( xi + 2 )
f iv ( xi ) = 4
+ O ( h2 ) Error
h
ME 261 .. Numerical Differentiation

Sample Questions
1. Derive the finite difference formula of first derivative with an
error of O(h4) using central finite difference approximation.
2. Derive the finite difference formula of first derivative with an
error of O(h2) using forward finite difference approximation.
3. Derive the finite difference formula of first derivative with an
error of O(h3) using forward finite difference approximation.
4. Derive the backward finite difference formula of first derivative
with an error of O(h3).
5. Derive the finite difference formula of second derivative with an
error of O(h4) using central finite difference approximation.
6. Derive a three-point central difference formula for second
derivative.
ME 261 .. Numerical Differentiation

Improvement of Finite Difference Formula


1. Decreasing step size, h
2. Using a formula of higher-order accuracy
3. Using Richardson’s extrapolation
Total error = Truncation error + Round-off error A common concept is that if
h decreases, the solution
will be more accurate. But
this is not true necessarily.
After a limit of step size (h)
is reached, the truncation
errors reduce but the round
off error increases. Finally,
the round off error becomes
dominant.
ME 261 .. Numerical Differentiation

Richardson’s Extrapolation Scheme


It is one of the error-correction techniques to improve the results
of numerical differentiation based on the derivative estimates
themselves. This method uses two estimates of a derivative to
compute a third, a more accurate approximation.
Say, f ( xi +1 ) − f ( xi −1 )
D = f ( x) = + O ( h2 )
h
Using CDS, we obtain the derivative with two different h values as
D(h1) and D(h2) respectively.
We can write, D  D ( h1 ) + E ( h1 ) , D  D ( h2 ) + E ( h2 )
h12
Now, error, E ( h1 ) = f  ( xi ) = eh12
6
h22
Similarly, E ( h2 ) = f  ( xi ) = eh22
6
ME 261 .. Numerical Differentiation

Richardson’s Extrapolation Scheme


Then D  D ( h2 ) + eh22
D  D ( h1 ) + E ( h1 ) = D ( h2 ) + E ( h2 ) D ( h2 ) − D ( h1 )
 D ( h2 ) + h22 + O ( h 4 )
 D ( h1 ) + eh = D ( h2 ) + eh
1
2 2
2 h12 − h22
D ( h2 ) − D ( h1 ) D ( h2 ) − D ( h1 )
e=  D ( h2 ) + + O ( h4 )
h12 − h22  h1 
2

  −1
 h2 
ME 261 .. Numerical Differentiation

Question: Consider the following ODE


d 2Y dY
10 + 4 + 6Y = 2 X 2

dX 2 dX
With reference to Taylor Series expansions, derive the equivalent
central-difference approximations to the ODE for the following two
different levels of truncation error.
a) Order of error of ΔX2 (O(h2))
b) Order of error of ΔX4 (O(h4))

(a) Taylor’s series expansion:


h2 h3
Y ( X i +1 )  Y ( X i ) + hY  ( X i ) + Y  (" X i ) + Y  ( X i ) + O ( h 4 ) (1)
2! 3!
h2 h3
Y ( X i −1 )  Y ( X i ) − hY  ( X i ) + Y  (" X i ) − Y  ( X i ) + O ( h 4 ) (2)
2! 3!
ME 261 .. Numerical Differentiation
(First Derivative)
Finite difference approximations of derivatives are derived from
the approximations of Taylor’s series expansion.
i−2 i−1 i i+1 i+2
x
Xi−1 Y’(Xi) Xi Xi+1
h
h3
• From (1) − (2) Y ( X i +1 ) − Y ( X i −1 ) = 2hY  ( X i ) + 2 Y  ( X i ) +
3!

dY Y ( X i +1 ) − Y ( X i −1 )
Thus, = + O ( h2 ) Error (3)
dX 2h

This is called Central Difference Scheme (CDS) / Approximation for dY/dX


[3 points formula]
ME 261 .. Numerical Differentiation
(Second Derivative)
Finite difference approximations of derivatives are derived from
the approximations of Taylor’s series expansion.
i−2 i−1 i i+1 i+2
x
Xi−1 Y’(Xi) Xi Xi+1
h
h2
• From (1) + (2) Y ( X i +1 ) + Y ( X i −1 ) = 2Y ( X i ) + 2 Y  ( X i ) + O ( h 4 )
2!

d 2Y Y ( X i −1 ) − 2Y ( X i ) + Y ( X i +1 )
Thus,
dX 2
=
h2
+ O ( h 2
) Error (4)

This is called Central Difference Scheme (CDS) / Approximation for d2Y/dX2


[3 points formula]
ME 261 .. Numerical Differentiation

Given differential equation:


d 2Y dY
10 + 4 + 6Y = 2 X 2

dX 2 dX
• Using (3) and (4)
 Y ( X i −1 ) − 2Y ( X i ) + Y ( X i +1 )   Y ( X i +1 ) − Y ( X i −1 ) 
10  2  + 4   + 6Y ( X i ) = 2 X i
2

 h   2 h 
 10 Y ( X i −1 ) − 2Y ( X i ) + Y ( X i +1 )  + 2h Y ( X i +1 ) − Y ( X i −1 )  + 6h 2Y ( X i ) = 2 X i2 h 2
 10Y ( X i −1 ) − 20Y ( X i ) + 10Y ( X i +1 ) + 2hY ( X i +1 ) − 2hY ( X i −1 ) + 6h 2Y ( X i ) = 2 X i2 h 2
 ( 2h + 10 ) Y ( X i +1 ) + ( 6h 2 − 20 ) Y ( X i ) + (10 − 2h ) Y ( X i −1 ) = 2 X i2 h 2

This is the equivalent central difference approximation of the


given differential equation. Error
O(h2)
ME 261 .. Numerical Differentiation

Home Task / Class Practice

Solution
 3

( r + r h )  ( r + 2h ) −  4r + 2r h + rh − 2   ( r + h ) + ( 6r 3 + 2rh 2 ) ( r )
3 2 3 2 2 h
 
 3 h3 
−  4r − 2r h + rh +   ( r − h ) + ( r 3 − r 2 h )  ( r − 2h ) = 0
2 2

 2

You might also like