Numerical Integration: Simpson's rule
Simpson's rule
Simpson's rule can be derived by approximating the function on the interval by connecting three consecutive points of the partition with a parabola, then treating the next set of three points in the partition in the same way, and continuing until you reach the end of the interval , for a partition of equidistant points on the interval with mesh size . So we assume that is even, say . The figure below visualizes the situation for .
The parabola can be found via Lagrange interpolation and the formula is
We can now look at a refined partition. The points of the partition are with and we can divide them into groups of 3: for . At each sub-interval we approximate the integral
Above we have already derived the approximation formula for each sub-interval:
Simpson's rule For a 'neat' function on the interval we have
In case we allow points halfway through a sub-interval, we can also rewrite Simpson's rule, as
Simpson's formula trapezoid rule midpoint-Riemann sum
We already know that the truncation error of the midpoint Riemann sum and the trunctation error of the trapezoidal rule are quadratic in mesh size ; so Simpson's rule is at least quadratic in , but in reality Simpson's rule is an even better approximation.
Programming task
Write a function SimpsonRule(f,a,b,n)
that implements Simpson's rule.
Apply your function with in the following two cases: