C1 L3
C1 L3
Chapter 1 Lecture 3
Numerical Differentiation
The Taylor Series expansion (Forward Taylor Series expansion) of the
function f at xi 1 is given by
f " ( xi ) 2
f ( n ) ( xi ) n
f ( xi 1 ) f ( xi ) f ' ( xi )h
h ...
h Rn
2!
n!
f ( n 1) ( ) n 1
h
where Rn
is a remainder term.
(n 1)!
Truncate the series after the first derivative term:
f ( xi 1 ) f ( xi ) f ' ( xi )h R1
This equation can be solved for
f ' ( xi )
f ( xi 1 ) f ( xi ) R1
h
h
Numerical Differentiation
f ( xi 1 ) f ( xi ) R1
f ' ( xi )
h
h
First-order
approximation
Truncation error
Numerical Differentiation
f (x)
f ( xi 1 )
f ' ( xi )
f ( xi )
h
xi
xi 1
f ( xi 1 ) f ( xi ) R1
f ' ( xi )
h
h
Numerical Differentiation
Here
f " ( ) 2
h
2
R1 f " ( )
h O ( h)
h
2
R1
R1
f " ( )
h
h
4
The equation
f ( xi 1 ) f ( xi ) R1
h
h
f ( xi 1 ) f ( xi )
O ( h)
h
f ' ( xi )
f " ( xi )
f (3) ( xi ) 2 f ( 4 ) ( xi ) 3
O (h)
h
h
h ........
2!
3!
4!
f (x)
f ( xi )
f ( xi 1 )
xi 1
Let
h xi xi 1
xi
so that
f ( xi 1 ) f ( xi h)
f " ( xi ) 2 f ( 3) ( xi ) 3
f ( xi ) f ' ( xi )h
h
h .......
2!
3!
f ( xi 1 ) f ( xi ) f ' ( xi )h R1
f ' ( xi )
f ( xi ) f ( xi 1 )
O ( h)
h
f " ( xi )
f (3) ( xi ) 2
O ( h)
h
h .......
2!
3!
Forward :
f " ( xi ) 2 f (3) ( xi ) 3
f ( xi 1 ) f ( xi ) f ' ( xi )h
h
h ......
2!
3!
Backward :
f " ( xi ) 2 f ( 3) ( xi ) 3
f ( xi 1 ) f ( xi ) f ' ( xi )h
h
h .......
2!
3!
Forward Backward:
f ( 3) ( xi ) 3
f ( xi 1 ) f ( xi 1 ) 2 f ' ( xi ) h
h ......
3!
f (3) ( xi ) 2
2h f ' ( xi )
h ......
3!
f ( xi 1 ) f ( xi 1 )
f (3) ( xi ) 2
f ' ( xi )
h .......
2h
3!
f ( xi 1 ) f ( xi 1 ) f ( 3) ( xi ) 2
f ' ( xi )
h .......
2h
3!
f ( xi 1 ) f ( xi 1 )
O(h 2 )
2h
where
f ( 3) ( xi ) 2 f (5) ( xi ) 4
O(h )
h
h ......
3!
5!
2
f (x)
f ( xi 1 )
f ' ( xi )
f ( xi )
f ( xi 1 )
xi 1
xi
xi 1
Example 1
Solution
f ( x) 0.1x 4 0.15 x 3 0.5 x 2 0.25 x 1.2
The derivative of f(x) is
xi 1 0
f ( xi 1 ) f (0) 1.2
xi 0.5
f ( xi ) f (0.5) 0.925
xi 1 1.0
f ( xi 1 ) f (1.0) 0.2
Solution
Solution
Solution
0.9125 1.0
100% 9.6%
0.9125
Solution
xi 1 0.25
f ( xi 1 ) f (0.25) 1.10351563
xi 0.5
f ( xi ) f (0.5) 0.925
xi 1 0.75
f ( xi 1 ) f (0.75) 0.63632813
Solution
Solution
0.9125 0.934
100% 2.4%
0.9125
Solution
h=0.5
Backward
Forward
h=0.25
t 39.7%
t 21.75%
t 58.9%
t 26.5%
t 9.6%
t 2.4%
Centered
For both step sizes, the centered difference approx. is more accurate
than forward and backward differences. Also as predicted by the
Taylor series analysis, halving the step size approximately halves the
error of backward and forward difference and quarters the error of
the centered difference.
f " ( xi ) 2 f ( 3) ( xi ) 3
f ( xi 1 ) f ( xi ) f ' ( xi )h
h
h ......
2!
3!
(2)
f ( xi 2 ) 2 f ( xi 1 )
f " ( xi )
where
f ( xi 2 ) 2 f ( xi 1 ) f ( xi )
O(h)
2
h
f " ( xi )
where
f ( xi ) 2 f ( xi 1 ) f ( xi 2 )
O ( h)
2
h
f " ( xi )
where
f ( xi 1 ) 2 f ( xi ) f ( xi 1 )
O ( h)
h2
1
O( h) 121 f ( 4 ) ( xi )h 2 360
f ( 6 ) ( xi )h 4 ......
f ( xi 1 ) f ( xi ) f ( xi ) f ( xi 1 )
h
h
f " ( xi )
h
Example 6
f ( x) 25 x 3 6 x 2 7 x 88
at x=2 using step sizes of h=0.25 and 0.125. Compare
your estimates with the true value of the second
derivative. Interpret your results on the basis of the
remainder term of the Taylor series expansion.
Solution
f ( x) 25 x 3 6 x 2 7 x 88
f ' ( x) 75 x 2 12 x 7
f " ( x) 150 x 12
The true value of the second derivative at x=2 is
Solution
xi 1 1.75
f ( xi 1 ) f (1.75) 39.85938
xi 2
f ( xi ) f (2) 102
xi 1 2.25
f ( xi 1 ) f (2.25) 182.1406
h=0.25
f ( xi 1 ) 2 f ( xi ) f ( xi 1 )
h2
f (2.25) 2 f (2) f (1.75)
f " ( 2)
288
2
(0.25)
f " ( xi )
Solution
h=0.125
xi 1 1.875
f ( xi 1 ) f (1.875) 68.82617
xi 2
f ( xi ) f (2) 102
xi 1 2.125
f ( xi 1 ) f (2.125) 139.6738