Professional Documents
Culture Documents
Numerical Derivatives
In this section we will see how to estimate the value of a derivative based on
knowing only certain function values. This is typical for many applications not to
know the exact function you are dealing with but rather a set of values for it.
The methods that are used tend to separate themselves into methods for values of
the independent variables that are equally spaced and those that are not.
Equally Spaced Data Points
If we consider three values for x: xi-1, xi, and xi+1 with xi-1 < xi < xi+1 we can form the
slopes of various secant lines with the corresponding y values yi-1=f(xi-1), yi=f(xi) and
yi+1=f(xi+1) to estimate the derivative.
Forward Differences
yi yi 1
f ' xi 1
xi xi 1
yi 1 yi
f ' xi
xi 1 xi
Backward Differences
f ' xi 1
yi yi 1
xi xi 1
yi 1 yi
f ' xi
xi 1 xi
f(x)
yi+1
yi
yi-1
xi-1 xi
xi+1
Central Difference
f(x)
yi+1
yi 1 yi 1
f ' xi
xi 1 xi 1
yi
yi-1
xi-1 xi
xi+1
If we assume the data are evenly spaced so that xi-xi-1 = h = xi+1-xi the formulas
below become:
Forward Difference
Backward Difference
Central Difference
y y
f ' xi i 1 i
h
yi 1 yi
f ' xi
h
yi 1 yi 1
f ' xi
2h
If you look in each of these formulas we are only using two pieces of
information. This means we are probably not as accurate as we can be. What if
we would like to estimate the value of the derivative at xi-1 but make use of all
three data points?
yi 1 4 yi 3 yi 1
f ' xi 1
xi 1 xi 1
f ' xi 1
3 yi 1 4 yi yi 1
xi 1 xi 1
Both of these formulas come from writing out the Lagrange Interpolating
polynomial for these three points, taking the derivative then plugging in the value
you want.
p ( x) yi 1
( x xi )( x xi 1 )
( x xi 1 )( x xi 1 )
( x xi 1 )( x xi )
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )
p ' ( x) yi 1
2 x xi xi 1
2 x xi 1 xi 1
2 x xi 1 xi
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )
p ' ( x) yi 1
2 x xi xi 1
2 x xi 1 xi 1
2 x xi 1 xi
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )
p ' ( xi 1 ) yi 1
2 xi 1 xi xi 1
2 xi 1 xi 1 xi 1
2 xi 1 xi 1 xi
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )
p ' ( xi 1 ) yi 1
xi 1 xi xi 1 xi 1
xi 1 xi 1
xi 1 xi
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )
p ' ( xi 1 ) yi 1
h 2 h
2h
h
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )
p ' ( xi 1 ) yi 1
3h
2h
h 3 yi 1 2 yi yi 1 3 yi 1 4 yi yi 1
i
i 1
2
2
2
2h
h
2h
2h
h
2h
2h
yi 1 4 yi 3 yi 1
f ' xi 1
xi 1 xi 1
p( x) yi 1
p ( x) yi 1
( x xi )( x xi 1 )
( x xi 1 )( x xi 1 )
( x xi 1 )( x xi )
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )
x 2 xi x xi 1 x xi xi 1
x 2 xi 1 x xi 1 x xi 1 xi 1
x 2 xi 1 x xi x xi 1 xi
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )
f ' ( x) p' ( x) yi 1
2 x xi xi 1
2 x xi 1 xi 1
2 x xi 1 xi
yi
yi 1
( xi 1 xi )( xi 1 xi 1 )
( xi xi 1 )( xi xi 1 )
( xi 1 xi 1 )( xi 1 xi )
Second derivative estimates rely on writing out the Taylor Series for a modified
version of the function f(x). We write out the Taylor Series for f(x+h) treating x as
a constant and h as the variable and expanding at the point 0.
f ' ' ( x) 2
f ( x) 4
f ( x h) f ( x h) 2 f ( x ) 2
h 2
h
2!
4!
( 4)
f
( x) 4
2
f ( x h) 2 f ( x ) f ( x h) f ' ' ( x ) h 2
h
4!
1
f ( 4 ) ( x) 2
f ( x h) 2 f ( x ) f ( x h) f ' ' ( x ) 2
h
2
h
4!
Example:
xi
yi
Two-Point Estimates:
4 1 3
53 2
3 4 1
f ' (5)
75 2
f ' (3)
Forward
4 1 3
53 2
3 4 1
f ' (7)
75 2
f ' (5)
f ' (5)
3 1 2 1
73 4 2
Central
Backward
73
4 2
Forward
73
4
2
Backward
1
4
2
(
4
)
1
22
4
Second Derivative
(h=2)