The error estimate for Simpson's rule is given by:
main.m36 chars2 lines
Where S(h/2)
and S(h)
are the approximations obtained using Simpson's rule with step sizes h/2
and h
respectively.
Here's an implementation to approximate an integral using the repeated Simpson's rule and calculate the error:
main.m430 chars17 lines
To use this function, simply provide the function to integrate f
, the lower and upper limits of integration a
and b
, and the number of steps N
. The function returns the approximate value of the integral, I
, and the estimated error, error
.
main.m232 chars10 lines
Note that to use Simpson's rule, the number of steps N
should be a multiple of 2.
gistlibby LogSnag