![]() |
||||
|
Gnotide Nowcasting Personal Information |
Adaptive QuadratureHere is a very simple implementation in Matlab of an adaptive quadrature algorithm for approximating the integral of a function f(x) using a simpler simpson 1/3 rule.
Example: If we are interested in the value of the defined integral of the function f(x)=exp(-x) in the limits [0,100] an analytical solution can be derived easily as F(x) = -exp(-100)-(-exp(-0)) = -(3.72007597602E-44) + 1 = 1 (with normal precision in any standar computer) Using the above function for the simpson 1/3 rule "simpson1_3('exp(-(x))',0,100)", a rough stimation ban be obtained equal to 16.16667, what is really far away from real value. Using the adaptive version, a much more acurate value of 1.002 is obtained even using a tolerance of 0.1. adaptative(0,100,'exp(-(x))',.1) In the figure, it is possible to see, how the points used for the adaptive method are denser where the slope is high, describing better the shape of the equation, and it has lower density where the function is almost flat, saving computational time.
|
|||
| e-mail: jmfernan (at) gnuwater.com || internal e-mail |