Lecture08 - Numerical Differentiation
Lecture08 - Numerical Differentiation
Statistics
Lecture 8:
Numerical Differentiation
Objectives
Introduction
Taylor Series
Forward difference method
Backward difference method
Central difference method
y f ( xi x) f ( xi )
x x
dy f ( xi x) f ( xi )
x lim 0
dx x
b
I f ( x)dx
a
y f ( x i x ) f ( x i ) dy f ( x i x ) f ( x i )
lim
x x dx x 0 x
2!
f 3 xi f n xi
xi1 xi ...
3
xi 1 xi n Rn
3! n!
f n1
Rn xi1 xi n1
n 1!
f '' xi
f xi 1 f xi f xi xi 1 xi
'
xi1 xi 2 2nd order
2! approximation
Finally
f '' xi
f xi 1 f xi f xi xi 1 xi
'
xi1 xi 2
2!
f 3 xi f n xi
xi 1 xi ...
3
xi 1 xi n Rn
3! n!
where
f n1
Rn xi1 xi n1
n 1!
ξ is a value of x that lies somewhere between xi and xi+1.
Limitations
ξ is not exactly known but lies somewhere between xi and xi+1
To evaluate Rn, the (n+1) derivative of f (x) has to be determined. To
do this f (x) must be known
if f (x) was known there would be no need to perform the Taylor
series expansion!!!
Modification
Rn = O(hn+1) the truncation error is of the order of hn+1 . (h = xi+1 – xi)
If the error is O(h), halving the step size will halve the error.
If the error is O(h2), halving the step size will quarter the error.
In general, the truncation error is decreased by addition of more
terms in the Taylor series.
f ( xi 1 ) f ( xi ) f ' ' ( x i )
f ' ( xi ) h O(h 2 ) (2)
h 2
Given that f“(x) can be approximated by:
f ( x i 2 ) 2 f ( xi 1 ) f ( x i )
f ' ' ( xi ) O ( h) (3)
h2
Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 14
Forward Difference Formulas- 1st derivative
f ( x i 3 ) 4 f ( x i 2 ) 5 f ( xi 1 ) 2 f ( xi )
f ' ' ( xi ) O(h 2 )
h2
f ( xi ) 2 f ( xi 1 ) f ( xi 2 )
f ' ' ( xi ) 2
O ( h)
h
2 f ( x i ) 5 f ( x i 1 ) 4 f ( xi 2 ) f ( xi 3 )
f ' ' ( xi ) 2
O ( h 2
)
h
Hence f ( xi 1 ) f ( xi 1 )
f ' ( xi ) O(h 2 )
2h
Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 19
Centered Difference Formulas- 1st derivative [O(h4)]
f ( xi 1 ) 2 f ( xi ) f ( xi 1 )
f ' ' ( xi ) 2
O ( h 2
)
h
for f’’(x)
f ( xi 2 ) 16 f ( xi 1 ) 30 f ( xi ) 16 f ( xi 1 ) f ( xi 2 ) 4
f ' ' ( xi ) 2
O ( h )
12h
Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 22
Error Analysis
a)Forward difference
1st derivative computation
First derivative:
f ( xi 2 ) 4 f ( xi 1 ) 3 f ( xi )
f ' ( xi )
2h
f (1) 4 f (0.75) 3 f (0.5)
f ' (0.5) 0.859375 εt = 5.82%
2(0.25)
True value=-0.9125
Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 26
Example 1 - Solution
Second derivative:
f ( xi 3 ) 4 f ( xi 2 ) 5 f ( xi 1 ) 2 f ( xi )
f ' ' ( xi )
h2
(1.94336) 4(0.2) 5(0.636328) 2(0.925)
f ' ' (0.5) 2
39.6
(0.25)
Dr. M. Hrairi MTH2212 - Computational Methods and Statistics 27
Example 1 - Solution