L9-NumericalDifferentiation
L9-NumericalDifferentiation
NUMERICAL METHODS
Numerical Differentiation
f ' ( xi ) f " ( xi ) 2 f ( n) ( xi ) n
f ( xi 1 ) f ( xi ) h h h Rn
1! 2! n!
f ( n 1) () ( n 1)
Rn h O(hn+1),
(n 1)!
If we truncate the series after the 1st derivative term
f ' ( xi )
f ( xi 1 ) f ( xi ) h R1
1!
Solve for the 1st derivative
' f ( xi 1) f ( xi )
f ( xi ) O ( h)
h
f ( xi 1) f ( xi ) f ( xi ) 1st forward divided difference
' f ( xi )
f ( xi ) O
( h)
h 1st order accurate
order of the
1st derivative truncation error
estimate
Forward Divided Difference method uses the value of points in
front of or at the point where the derivative is calculated.
First derivative with backward divided difference
h xi xi 1 : step size
' f ( xi ) f ( xi 1)
f ( xi ) O ( h)
h
' f ( xi )
f ( xi ) O
( h)
h 1st order accurate
order of the
1st derivative truncation error
estimate
First derivative with center divided difference
xi 1 xi 1 2h
f ' ( xi ) f (3) ( xi ) 3
f ( xi 1 ) f ( xi 1 ) 2 h2 h
1! 3!
f ( n) ( xi ) n
2 h Rn
n!
n is odd.
Truncate the series after the 1st derivative term and solve for the
1st derivative
'
f ( xi 1) f ( xi 1) 2 f ( xi )h R1 f (3) () 3
R1 h
(3)!
' f ( xi 1 ) f ( xi 1 )
f ( xi ) O(h 2 )
2h
order of the 2nd order accurate
1st derivative truncation error
estimate
f ' ( xi ) f " ( xi ) 2 f ( n) ( xi ) n
f ( xi 1 ) f ( xi ) h h h Rn
1! 2! n!
f ' ( xi ) f " ( xi ) 2 f ( n)
( xi )
f ( xi 2 ) f ( xi ) 2h ( 2h ) (2h n ) Rn
1! 2! n!
xi 1 xi h
xi 2 xi 2h
Truncate the series after the 2nd derivative term
f ' ( xi ) f " ( xi ) 2
f ( xi 1 ) f ( xi ) h h R2
1! 2!
f ' ( xi ) f " ( xi )
f ( xi 2 ) f ( xi ) 2h (2h) 2 R2
1! 2!
Multiply f(xi+1) by 2 and subtract that from f(xi+2)
f ( xi 2 ) 2 f ( xi 1 ) f ( xi ) f ( xi )h 2 O (h3 )
Solve for the 2nd derivative
'' f ( xi 2 ) 2 f ( xi 1) f ( xi )
f ( xi ) O
( h)
2
h
order of the
2nd derivative truncation error
estimate
f ' ( xi ) f " ( xi ) 2
f ( xi 1 ) f ( xi ) h h R2
1! 2!
f ' ( xi ) f " ( xi )
f ( xi 2 ) f ( xi ) 2h (2h) 2 R2
1! 2!
Multiply f(xi-1) by 2 and subtract that from f(xi-2)
f ( xi 2 ) 2 f ( xi 1 ) f ( xi ) f ( xi )h 2 O(h3 )
Solve for the 2nd derivative
'' f ( xi 2 ) 2 f ( xi 1) f ( xi )
f ( xi ) O
( h)
2
h
order of the
2nd derivative truncation error
estimate
f ' ( xi ) f " ( xi ) 2 f ( n) ( xi ) n
f ( xi 1 ) f ( xi ) h h h Rn
1! 2! n!
f ' ( xi ) f " ( xi ) 2 f (n) ( xi ) n
f ( xi 1) f ( xi ) h h h Rn
1! 2! n!
Add these terms and truncate the series after the 2nd derivative term
f ( xi 1) f ( xi 1) 2 f ( xi ) f " ( xi )h 2 O(h 4 )
" f ( xi 1 ) 2 f ( xi ) f ( xi 1 )
f ( xi ) O(h 2 ) 2nd order accurate
h2
High Accuracy Differentiation Equations
• High-accuracy divided-difference formulas can be generated by
including additional terms from the Taylor series expansion.
1st derivative with forward divided difference
f ( xi ) 2
f ( xi 1 ) f ( xi ) f ( xi )h h R2
2
f ( xi 1 ) f ( xi ) f ( xi )
f ( xi ) h O(h 2 )
h 2
f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
f ( xi )
h2
f ( xi 1 ) f ( xi ) f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
f ( xi ) 2
h O ( h 2
)
h 2h
f ( xi 2 ) 4 f ( xi 1 ) 3 f ( xi )
f ( xi ) O(h 2 )
2h
f ( xi ) 2
f ( xi 1 ) f ( xi ) f ( xi )h h R2
2
f ( xi ) f ( xi 1 ) f ( xi )
f ( xi ) h O(h 2 )
h 2
f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
f ( xi )
h2
f ( xi 2 ) 4 f ( xi 1 ) 3 f ( xi )
f ( xi ) O( h 2 )
2h
1st derivative with centered divided difference
f ( xi 2 ) 8 f ( xi 1 ) 8 f ( xi 1 ) f ( xi 2 )
f ( xi ) O( h 4 )
12h
Derive the formula for the centered divided difference for the
1st derivative and show that it’s 4th order accurate.
Forward Divided Difference
Backward Divided Difference
Centered Divided Difference
Example: Determine the 1st derivative of
f ( x) 0.1x 4 0.15x 3 0.5x 2 0.25x 1.2
Time (s) 0 1 2 3 4 5 6 7 8
Position (m) 0 0.7 1.8 3.4 5.1 6.5 7.3 8.0 8.4
v(5) 0.85m / s
2
a(5) 0.1m / s
Solution
Richardson Extrapolation
34
• D is the true value but unknown and D(h1) is an
approximation based on the step size h1. Reducing the step size
to half, h2 =h1/2, we obtained another approximation D(h2).
• By properly combining the two approximations, D(h1) &
D(h2), the error is reduced to O(h4).
4 1
h2 h1 / 2 D D(h2 ) D(h1 )
3 3
Example: Determine the 1st derivative of
f ( x) 0.1x 4 0.15x 3 0.5x 2 0.25x 1.2
38
f ( x) f ( xi 1 )
x xi x xi 1 f ( x ) x xi 1 x xi 1 f ( x ) x xi 1 x xi
xi 1 xi xi 1 xi 1 i
xi xi 1 xi xi 1 i 1
xi 1 xi 1 xi 1 xi
2 x xi xi 1 2 x xi 1 xi 1 2 x xi 1 xi
f ( x) f ( xi 1 ) f ( xi ) f ( xi 1 )
xi 1 xi xi 1 xi 1 xi xi 1 xi xi 1 xi 1 xi 1 xi 1 xi
f (0.8) 0.715
Solution