# How does simpsons rule work

can anyone tell me how it works, like visually, what does it do. Im curious.
iv heard its a three point approximation whereas the trapazoidal rule is a two point approximation. But im not entirely sure i understand.

HallsofIvy
Homework Helper
The trapezoid method approximates the curve, between successive points, by a straight line while Simpson's rule uses three points at a time and approximates the curve by the parabola passing through the three points.

Suppose your function is f(x) and you take three points, $(x_0, f(x_0), (x_1, f(x_1), (x_2, f(x_2)), equally spaced on the x-axis. For simplicity, take the x-values to be [itex]x_0= x_1- h$, $x_1$, and $x_2= x_1+ h$ where h is the distance between succesive x values so the points themselves are $(x_1- h, f(x_0)), (x_1, f(x_1)), (x_1+ h,f(x_2))$.

The equation of a parabola through $(x_1, f(x_1))$ can be written $y= a(x- x_1)^2+ b(x- x_1)+ f(x_1)$. Taking $x= x_0= x_1- h$ we get $y= f(x_0)= ah^2+ bh+ f(x_1)$. Taking $x= x_2= x_1+ h$ we get $y= f(x_2)= ah^2- bh+ f(x_1)$.

Adding those two equations, $f(x_2)+ f(x_0)= 2ah^2+ 2f(x_1)$ so that
$$ah^2= \frac{f(x_2)+ f(x_0)}{2}- f(x_1}= \frac{f(x_2)- 2f(x_1)+ f(x_0)}{2}$$]
and
$$a= \frac{f(x_0)+ 2f(x_1)+ f(x_2)}{2h^2}[/itex] Subtracting those two equations, $f(x_2)- f(x_0)= 2bh$ so that [tex]b= \frac{f(x_2)- f(x_0)}{2h}$$

Now, $\int_{x_0}^{x_2}a(x-x_1)^2+ b(x-x_1)+ f(x_1) dx= \int_{x_1-h}^{x_1+h} a(x-x_1)^2+ b(x-x_1)+ f(x_1) dx$$= (1/3)ah^3+ (1/2)bh^2+ f(x_1)h- (1/3)a(-h)^3- b(-h)^2- f(x_1)(-h)= (2/3)ah^3+ 2f(x_1)h[itex] so b really isn't important. The integral of the parabola through [itex](x_1-h, f(x_0)), (x_1, f(x_1)), (x_1+h,f(x_2))$ is
$$(2/3)ah^3+ 2f(x_1)h= (2/3)\frac{f(x_0)- 2f(x_1)+ f(x_2)}{2h^2}h^3+ 2f(x_1)h$$
[tex]= \frac{2(f(x_0)- 2f(x_1)+ f(x_2)}{3}h+ 2f(x_1)h= h\frac{2f(x_0)- 4f(x_1)+ 2f(x_2)}{3}[/itex]

That is the formula for exactly 3 data points. If we have more, we can separte into groups of three and do that for each such interval. Bacause the overlap at the ends, we must have an odd number of points to do that.

For example, if we had only an even number of points, $x_0, x_1, x_2, x_3$, our first parabola would be over $x_0, x_1, x_2$ but, even including $x_3$ as our first endpoint in the next interval we would have only $x_2, x_3$, not enough for a parabola. But with 5 points, we could have $x_0, x_1, x_2$, $x_2, x_3, x_4$. Similarly, with 6 points, an even number, we would have $x_0, x_1, x_2$, $x_2, x_3, x_4$, $x_4, x_4$ and not be able to complete the last parabola but with 7, an odd number, we would have $x_0, x_1, x_2$, $x_2, x_3, x_4$, $x_4, x_5, x_6$.

Now see what happens when we "attach" parabolas: on $x_0, x_1, x_2$ we have
[tex]h\frac{2f(x_0)- 4f(x_1)+ 2f(x_2)}{3}[/itex]
while on $x_2, x_3, x_4$
[tex]h\frac{2f(x_2)- 4f(x_3)+ 2f(x_4)}{3}[/itex]