Numerical Differentiation
Numerical Differentiation
• This yields to
f ( xi +1 ) − f ( xi −1 )
f ′( xi ) =
2h
• This formula is called the centered divided difference
formula and the error is of order O(h2).
Backward
Centered
• Combine equations:
f ′′( xi )
f ( xi + 2 ) = f ( xi ) + f ′( xi )(2h) + ( 2h) 2
2
−
f ′′( xi ) 2
2 f ( xi +1 ) = f ( xi ) + f ′( xi )h + h
2
_______________________________________
f ( xi + 2 ) − 2 f ( xi +1 ) = − f ( xi ) + f ′′( xi )h 2
Dr Muhammad Al-Salamah, Industrial Engineering, KFUPM
• Solve for f ''(xi):
f ( xi + 2 ) − 2 f ( xi +1 ) + f ( xi )
f ′′( xi ) =
h2
f ( xi ) − 2 f ( xi −1 ) + f ( xi − 2 )
f ′′( xi ) =
h2
f ( xi +1 ) − 2 f ( xi ) + f ( xi −1 )
f ′′( xi ) =
h2
HIGH-ACCURACY DIFFERENTIATION
FORMULAS
• The forward Taylor series expansion is:
f ' ' ( xi ) 2
f ( xi +1 ) ≈ f ( xi ) + f ′( xi )( xi +1 − xi ) + h
2
• From this, we can write
f ( xi +1 ) − f ( xi ) f ' ' ( xi )
f ′( xi ) ≈ − h
h 2
• By collecting terms:
− f ( xi + 2 ) + 4 f ( xi +1 ) − 3 f ( xi )
f ′( xi ) ≈
2h
• Inclusion of the 2nd derivative term has improved the
accuracy to O(h2).
• This is the forward divided difference formula for the
first derivative.
Dr Muhammad Al-Salamah, Industrial Engineering, KFUPM
FIGURE Forward Formulas
Solution
xi − 2 = xi − 2h = 1 − 0.5 = 0.5
xi −1 = xi − h = 1 − 0.25 = 0.75
xi = 1
xi +1 = xi + h = 1 + 0.25 = 1.25
+ 2 = xi + 2hIndustrial
Dr MuhammadxiAl-Salamah, = 1 + 0.5Engineering,
= 1.5 KFUPM
• In substituting the values:
4 k −1 D j +1,k −1 − D j ,k −1
D j ,k ≅
4 k −1 − 1
• The solution is terminated when
D1,k − D2,k −1
εa = 100% < ε s
D1,k
Solution
k 1 2 3
j h Dj,1 Dj,2 |εa| Dj,3 |εa|
1 0.25 3.717925 3.718372 0.003 3.718281 0.0002
2 0.125 3.718260 3.718287
3 0.0625 3.718280