| |||||||||
computer science, in the field of numerical analysis, Simpson's Rule is a way to get an approximation of an integral:
using an interpolating polynomial of higher degree. Simpson's rule belong to the family of rules derived from Newton-Cotes formulas. The most common is a quadratic polynomial interpolating at a, (a+b)/2, and b which gives us the polynomial:
From this Simpson's Rule is:
<math>
We want to have our polynomial on the form:
Assume we have the function values <math>a=x_0<math>, <math>\frac{a+b}{2}=x_1<math> and <math>b=x_2<math>. The situation will look like this, with our sampled function values at <math>f(a)<math>, <math>f\left(\frac{a+b}{2}\right)<math> and <math>f(b)<math>:
As this Simpson's rule apply to equidistant points, we know that <math>x_0 < x_1 < x_2<math> and that <math>x_1-x_0 = x_2-x_1<math>. This means we may transport our solution to the intervals formed by <math>-h, 0, h<math> such that
We need to interpolate these values and function values with a polynomial and form our equations:
Which yields:
We then integrate our polynomial:
\frac{f(h) - f(-h)}{2h}x + f(0) dx =<math>
\frac{f(h) - f(-h)}{4h}x^2 + f(0)x \right]_{-h}^h =<math>
\frac{f(h) - f(-h)}{4h}h^2 + f(0)h +<math>
\frac{f(h) - f(-h)}{4h}h^2 + f(0)h =<math>
2f(0)h<math>
Substitute back our original values:
2f\left(\frac{a+b}{2}\right) \left(\frac{b-a}{2}\right) =<math>
2f\left(\frac{a+b}{2}\right) \left(\frac{b-a}{2}\right) = <math>
6f\left(\frac{a+b}{2}\right) \right) = <math>
To examine the accuracy of the rule, take <math>c = \frac{a+b}{2}<math>, so
Using integration by parts we get:
and
where α and β are constants that we can choose. Adding these expressions, we get:
Let's take α and β, so as to get Simpson's Rule:
and defining the function Py(x) by:
<math>P_y(x)=\left\{\begin{matrix} x-\alpha, & \mbox{if }a\le x \le c \\ x-\beta, & \mbox{if }c < x \le b \end{matrix}\right.<math>
we have
where
is the error value.