        

advertisement
Numerical First Derivatives
A function can be expanded about t0 as
f  t   f  t0    t  t0  f '  t0  

1
1
1
2
3
4
 t  t0  f ''  t0    t  t0  f ''' t0   t  t0  f IV t0 
2
6
24
1
5
 t  t0  f V  t 0  
120
(1)
Let t = t0+ and t = t0- .
f  t0     f  t 0    f '  t 0  
2
f  t0     f  t 0    f '  t 0  
2
2
2
f ''  t0  
3
f ''  t0  
3
f '''  t0  
4
f '''  t0  
4
6
6
24
24
f IV  t0  
f IV  t0  
5
120
5
120
f V  t0  
f V  t0  
Subtract (3) from (2).
f  t0     f  t0     2 f '  t0  
3
3
f '''  t0  
5
f '''  t0  
4
60
f V t0 
(4)
Solve for f’
f '  t0 ,   
f  t0     f  t0   
2

2
6
120
f V  t0 
(5)
Richardson’s Extrapolation
Make the calculation with /2
Equation (5) becomes
f '  t0 ;  / 2  
f  t0   / 2   f  t0   / 2 


2
24
f '''  t0  
4
16  120
f V  t0  (6)
Subtract (5) from 4 × (6)
3 f '  t0  
8 f  t0   / 2   f  t0     8 f  t 0   / 2   f  t 0   
2

3 4
f V  t0  (7)
4  120
Or
f '  t0 ;  / 2  
8 f  t 0   / 2   f  t0     8 f  t 0   / 2   f  t0   
6


4
4  120
f  t0  2   8   2 2
2
f V  t0  
6
(8)
(2)
(3)
The last term in (8) is the random truncation errors involved in evaluating f ~ 10-15
This term is approximately
2 f  t0   / 
(9)
The fV term is on the order of 5! = 120 × f(t0)
So that the total error is
  4 2 
Err    

 f  t0 
 
 4
Err    3 2 
    2  f  t0 

 

or
 5  2
or
  103
(10)
In double precision δ is approximately 1×10-3, a factor much larger than that used without the Richardson extrapolation.
f '  t0  
1
8 f  t0   / 2   f  t0     8 f  t0   / 2   f  t0    
6 
(11)
An example test code is in GDc1st.zip.
Figure 1 f' numeircal error versus delta (black line is simple equation), red has f''’ extrapolated out.
The function f is exp(-x2) The derivatives were calculated at x = 0.5. Note that there are more additions and subtractions
in the extraplated method, so that its error for small delta would be expected to be higher. The minimum at delta = 10-3
is pure chance, since the calculation in (10) uses a very approximated value for fV.
The plot was made with a lot of hand entries by the code in GDc1stPlot.zip.
Nlfit
Numerical derivatives can be used simply because the factor of four  Ncons in run time is far less than the coding
time required to use analytical derivatives. Nlfit uses (11) to evaluate numerical derivatives which require four extra
evaluations of fA for each constant at each data point.
Download