Integral of f

advertisement
Integral of f
The sum method is not the best way to find the integral of a function. The most
accurate method is to fit the derivative function to a set of parameters. Then this same set
of parameters define the integral of the fitted function Generalized Fermi Function.doc
htm. In principle the sum of the squares of the final function resulting from leaving out
each data point in turn is the standard deviation in the fitted function
../../../definitions/Random/Errinfun.doc. In practice this result usually comes directly
from the inverse of the second derivative matrix ..\..\ErrorMatrix\StdDev.doc htm. The
sum method is however extremely simple and provides a good test of the procedures
above. A figure showing the equality of the sum method below and the use of the error
matrix is in ..\..\nlfit\FermiFit\FermiStd.htm.
Not all fits, however, are made for the purpose of minimizing statistical standard
deviations. When the object is simply to find a representation of the integral of a
function a direct fit to the sum produced here is a good way to proceed. Beware of the
increasing systematic error as the sum proceeds.
Sum method
The code in for\sum.for is very simple.
The integral is defined by
x
F  x    f  t  dt
(1)
x1
This is given
 x  xI 1  I fi  fi 1
(2)
FI  I
 xi 1  xi 

2
2

 i 1
The systematic error in this is approximately that given by Traprule.doc
2
 xI  xI 1

 x1 
  xI  xI 1 

2
 Sys   f ' 
 (3)
  f '  x1   
2
N

 
 



A somewhat crude approximation to both values of f’ is the difference between the
beginning and middle values divided by half the range. For a peak this makes the two
ends have the same value with opposite signs so that this term approximately cancels.
2
   xI  xI 1 
 x  x


I
I 1

f
x

f
x

f
x








 f 

mid 
mid
1

 x1 
2



2
 
 Sys   



N
 xI  xI 1



x
/
2

 
(4)
1


2




  x  xI 1 
  x  xI 1  2 x1 
 f  I
 f  x1   I

2
N2

 

This can be added to the integral, but it still represents an error estimate.
The random error is
I
 2   2i 1
2
(5)
 Ran
 i
 xi1  xi 
2
i 1
Notice that the error never goes down. A function that integrates to zero will always
have a final error due to the finite accuracy of the intermediate evaluations. The random
error is added to the sum in for\sum.for
Figure 1 Sum of dfermi in Welcome.htm
Download