Numerical Differentiation PDF
Numerical Differentiation PDF
Introduction
• Some numerical algorithms require
evaluation of the derivative of a function.
DN +1 − DN ≥ DN − DN −1
• In the example,
0.0007 = D6 − D5 > D5 − D4 = 0.00012
Sources of error
• The truncation error εt comes from higher
terms in the Taylor series expansion:
f (x + h ) − f (x ) 1
f '= − hf "− !
h 2
• Round-off error εr must be expected since
real numbers don’t have exact
representation in binary.
Central-difference formulas
• Assume that f ∈C3[a,b] and that x-h, x, x+h
∈[a,b]. Then
f (x + h ) − f (x − h )
f ' (x ) ≈ + εt ( 2)
2h
where, there exists a number c=c(x) ∈[a,b]
such that
2 (3 )
h f (c )
εt = − = O(h )
2
6
Centered-formula of order O(h4)
Assume that f ∈C5[a,b] and that x-2h, x-h, x x
+h, x+2h ∈[a,b]. Then
− f ( x + 2h ) + 8 f ( x + h ) − 8 f ( x − h ) + f ( x − 2h )
f ' (x ) ≈ + εt
12h
(3)
where 4 (5 )
h f (c )
εt = −
30
=O h 4
( )
Example
Let f(x)=cos(x). Calculate approximations for
f’(0.8) using Eqs. (2) and (3) with step
sizes h=0.1, 0.01, 0.001, 0.0001 and
compare with true value f’(0.8) = -sin(0.8).
• Differentiating
• Differentiating
P4 ' (0.8) = −0.717353703
Differentiation using Limits
To approximate f ’(x) numerically, generate
a sequence
f ' (x ) ≈ Dk =
( −k
) ( −k
f x + 10 h − f x − 10 h )
( )
−k
2 10 h
− f 2 + 16 f1 − 30 f 0 + 16 f −1 − f −2
f " (x0 ) ≈
12h 2