 ## NM2 Simpson’s rule The figure above shows how Simpson’s rule approximates the area under the graph of a function $$f\left(x\right)$$ by the area under a parabola using two strips.

You will have evaluated definite integrals such as \begin{align*} \int_{1}^{3} & \left(x^{2}\right)dx \end{align*} before. In doing this, you are evaluating the area under the graph of $$f\left(x\right)=x^{2}$$ between $$x=1$$ and $$x=3.$$ This is only possible if you can find an antiderivative for $$x^{2}$$. In this example it is easy, the antiderivative is \begin{align*} F\left(x\right) & =\frac{1}{3}x^{3}+c,\text{ where c is a constant.} \end{align*} and \begin{align*} \int_{1}^{3}\left(x^{2}\right)dx & =F\left(3\right)-F\left(1\right)\\ & =\frac{1}{3}3^{3}+c-\left(\frac{1}{3}1^{3}+c\right)\\ & =\frac{26}{3}. \end{align*}

Sometimes it is not possible to find the antiderivative. In such cases you need to use a numerical method. Two common methods for calculating definite integrals are:

1. Simpson’s rule, and

2. The trapezoidal rule.

This module considers Simpson’s rule.

### Simpson’s Rule

Simpson’s rule estimates the value of the definite integral

\begin{align*} \int_{a}^{b}f\left(x\right)dx. \end{align*} Simpson’s rule estimates the area under the graph of $$f\left(x\right)$$ by approximating the function $$f\left(x\right)$$ by a parabola and calculating the area under the parabola. Each parabolic approximation is done over two strips. The accuracy of the Simpson’s Rule approximation increases as you use more strips. There must be an even number of strips.

Simpson’s rule has the form: \begin{align*} \int_{a}^{b}f\left(x\right)dx & \approx\frac{1}{3}h\left[y_{0}+4\sum_{i=1,3,5,\ldots}^{n-1}y_{i}+2\sum_{i=2,4,6,\ldots}^{n-2}y_{i}+y_{n}\right]\\ & =\frac{1}{3}h\left[y_{0}+4y_{1}+2y_{2}+4y_{3}+2y_{4}+\ldots+4y_{n-1}+y_{n}\right] & \left(1\right) \end{align*} where

1. $$n$$ is the number of strips. Note that $$n$$ must be even.

2. $$y_{i}=f\left(x_{i}\right)$$ are the values of $$f\left(x_{i}\right)$$ at the points $$x_{i}$$ where $$i=0,1,2,3\ldots,n$$. Note that $$x_{0}=a,$$ $$x_{n}=b.$$

3. $$h$$ is the width of each strip and \begin{align*} h & =\frac{b-a}{n}. \end{align*}

4. $$x_{1}=a+h,$$ $$x_{2}=a+2h,$$ $$x_{3}=a+3h,$$ $$\ldots$$ and so on.

Note that the value of the function at the odd numbered points are multiplied by four whereas the even numbered points are multiplied by two in equation $$\left(1\right)$$ above.

The accuracy of the Simpson’s Rule approximation of an integral increases as you use more strips.

#### Example 1

Using Simpson’s rule, find the value of \begin{align*} \int_{1}^{3} & \left(e^{2x}\sin\left(x\right)\right)dx \end{align*} using $$2$$ strips to an accuracy of $$3$$ decimal places. This integral may be evaluated and is approximately equal to $$100.96243981$$.

Solution:

Consider the figure below. Simpson’s rule approximates the real function by a parabola (shown in green/black dotted lines).1 Note that three points are needed to fit a parabola. The area given by Simpson’s rule is the shaded area under the parabola. From the graph we can see that Simpson’s rule will overestimate the area under the real graph from $$x=1$$ to $$x=2$$ and underestimate the area from $$x=2$$ to $$x=3.$$

We have $$n=2,$$ $$a=1,$$ $$b=3$$ and2 The first strip is from $$x=1$$ to $$x=2.$$ The second is from $$x=2$$ to $$x=3.$$ \begin{align*} h & =\frac{b-a}{2}\\ & =\frac{3-1}{2}\\ & =1. \end{align*}

Calculating the three points and the value of the function at those points we have:3 Note that the number of points $$p$$ and the number of strips $$n$$ are related by \begin{align*} p & =n+1. \end{align*} We stop calculating points when $$x_{n}=b.$$ In this example $$n=2$$ and there are $$3=2+1$$ points at which the function must be evaluated. They are $$x_{0},x_{1}$$ and $$x_{2}.$$

$$x_{0}=a=1$$ and $$y_{0}=e^{2\left(1\right)}\sin\left(1\right)=6.2176763.$$

$$x_{1}=a+h=1+1=2$$ and $$y_{1}=e^{2\left(2\right)}\sin\left(2\right)=49.6459573.$$

$$x_{2}=a+2h=1+2=3$$ and $$y_{3}=e^{2\left(3\right)}\sin\left(3\right)=56.9318746.$$

Now we substitute this in the Simpson’s rule formula $$\left(1\right).$$ We get \begin{align*} \int_{1}^{3}\left(e^{2x}\sin\left(x\right)\right)dx & =\frac{1}{3}h\left[y_{0}+4y_{1}+y_{2}\right]\\ & =\frac{1}{3}\left(1\right)\left[6.2176763+4\left(49.6459573\right)+56.9318746\right]\\ & =\frac{1}{3}\left[6.2176763+4\left(49.6459573\right)+56.9318746\right]\\ & =87.2444601. \end{align*} The answer, to three decimal places, is \begin{align*} \int_{1}^{3}\left(e^{2x}\sin\left(x\right)\right)dx & =87.244. \end{align*} This is well under the value of $$100.96243981$$. The percentage error is \begin{align*} \text{error} & =\frac{100.96243981-87.2444601}{100.96243981}\times100\\ & =13.6\%. \end{align*}

#### Example 2

Using Simpson’s rule, find the value of \begin{align*} \int_{1}^{3} & \left(e^{2x}\sin\left(x\right)\right)dx \end{align*} using $$4$$ strips to an accuracy of $$3$$ decimal places. This is exactly the same as Example 1 above except that we are using more strips.

Solution:

We have $$n=4,$$ $$a=1,$$ $$b=3$$ and \begin{align*} h & =\frac{b-a}{4}\\ & =\frac{3-1}{4}\\ & =0.5\,. \end{align*}

Now calculate the points and the value of the function at those points.

$$x_{0}=a=1$$ and $$y_{0}=e^{2\left(1\right)}\sin\left(1\right)=6.2176763.$$

$$x_{1}=a+h=1+0.5=1.5$$ and $$y_{1}=e^{2\left(1.5\right)}\sin\left(1.5\right)=20.0352224\,.$$

$$x_{2}=a+2h=1+1=2$$ and $$y_{3}=e^{2\left(2\right)}\sin\left(2\right)=49.6459573\,.$$

$$x_{3}=a+3h=1+1.5=2.5$$ and $$y_{3}=e^{2\left(2.5\right)}\sin\left(2.5\right)=88.8211415\,.$$

$$x_{4}=a+4h=1+2=3$$ and $$y_{4}=e^{2\left(3\right)}\sin\left(3\right)=56.9318746\,.$$

Now we substitute the $$y_{n}$$ values in the Simpson’s rule formula $$\left(1\right).$$ We get \begin{align*} \int_{1}^{3}\left(e^{2x}\sin\left(x\right)\right)dx & =\frac{1}{3}h\left[y_{0}+4\left(y_{1}+y_{3}\right)+2\left(y_{2}\right)+y_{4}\right]\\ & =\frac{0.5}{3}\left[6.2176763+4\left(20.0352224+88.8211415\right)\right.\\ & \quad\quad\left.+2\left(49.6459573\right)+56.9318746\right]\\ & =99.6444869\,. \end{align*} So the answer to three decimal places is \begin{align*} \int_{1}^{3}\left(e^{2x}\sin\left(x\right)\right)dx & =99.645\,. \end{align*} This is much closer to the actual value of $$100.96243981$$. The percentage error is now \begin{align*} \text{error} & =\frac{100.96243981-99.6444869}{100.96243981}\times100\\ & =1.3\% \end{align*} which is a huge improvement over the result in Example 1.

#### Example 3

Using Simpson’s rule, find the value of \begin{align*} \int_{1}^{3} & \left(e^{2x}\sin\left(x\right)\right)dx \end{align*} using $$6$$ strips to an accuracy of $$3$$ decimal places. This is exactly the same as Example 1 and 2 above, except that we are using more strips.

Solution:

We have $$n=6,\$$ $$a=1,$$ $$b=3$$ and \begin{align*} h & =\frac{b-a}{6}\\ & =\frac{3-1}{6}\\ & =\frac{1}{3}\,. \end{align*}

Now calculate the values at the seven points:

$$x_{0}=a=1$$ and $$y_{0}=e^{2\left(1\right)}\sin\left(1\right)=6.2176763.$$

$$x_{1}=a+h=1+1/3=4/3.$$ So $$y_{1}=e^{2\left(4/3\right)}\sin\left(4/3\right)=13.9880487\,.$$

$$x_{2}=a+2h=1+2/3=5/3.$$ So $$y_{3}=e^{2\left(5/3\right)}\sin\left(5/3\right)=27.9029025\,.$$

$$x_{3}=a+3h=1+1=2\,.$$ So $$y_{3}=e^{2\left(2\right)}\sin\left(2\right)=49.6459573\,.$$

$$x_{4}=a+4h=1+4/3=7/3.$$ So $$y_{4}=e^{2\left(7/3\right)}\sin\left(7/3\right)=76.8948872\,.$$

$$x_{5}=a+5h=1+5/3=8/3.$$ So $$y_{5}=e^{2\left(8/3\right)}\sin\left(8/3\right)=94.7136211\,.$$

$$x_{6}=a+6h=1+2=3.$$ So $$y_{6}=e^{2\left(3\right)}\sin\left(3\right)=56.9318746\,.$$

Now we substitute these values into the Simpson’s rule formula $$\left(1\right).$$ We get \begin{align*} \int_{1}^{3}\left(e^{2x}\sin\left(x\right)\right)dx & =\frac{1}{3}h\left[y_{0}+4\left(y_{1}+y_{3}+y_{5}\right)+2\left(y_{2}+y_{4}\right)+y_{6}\right]\\ & =\frac{1}{3}\frac{1}{3}\left[6.2176763\right.\\ & \quad\quad+4\left(13.9880487+49.6459573+94.7136211\right)\\ & \quad\quad+2\left(27.9029025+76.8948872\right)+56.9318746\left.\!\right]\\ & =100.6817377\,. \end{align*} The answer is, to three decimal places, \begin{align*} \int_{1}^{3} & \left(e^{2x}\sin\left(x\right)\right)dx=100.682\,. \end{align*} The percentage error is now \begin{align*} \text{error} & =\frac{100.96243981-100.6817377}{100.96243981}\times100\\ & =0.3\%. \end{align*}

### Error Reduction with Increasing Number of Strips

Examples 1, 2 and 3 above show that the Simpson’s Rule reduces error quickly with increased numbers of steps. This is summarised in the table below.

Number of Strips Value Obtained Error %
2 87.244 13.5
4 99.645 1.3
6 100.682 0.3

### Final Example

Approximate $$\int_{0}^{2}\frac{1}{1+x^{3}}dx$$ using Simpson’s rule with $$4$$ strips to $$5$$ decimal places.

Solution:

We have $$a=0$$, $$b=2$$, $$n=4$$ and \begin{align*} h & =\frac{b-a}{n}\\ & =\frac{2-0}{4}\\ & =0.5\,. \end{align*} Calculating the points, and the value of the function $$\frac{1}{1+x^{3}}$$ at them we have:

$$x_{0}=a=0$$ and $$y_{0}=1$$,

$$x_{1}=a+h=0.5$$ and $$y_{1}=1/\left(1+0.5^{3}\right)=0.888889$$,

$$x_{2}=a+2h=0+1$$ and $$y_{2}=1/\left(1+1^{3}\right)=0.5$$,

$$x_{3}=a+3h=0+1.5=1.5$$ and $$y_{3}=1/\left(1+1.5^{3}\right)=0.228571$$,

$$x_{4}=a+4h=0+2=2$$ and $$y_{4}=1/\left(1+2^{3}\right)=0.111111.$$

Now we substitute in eqn$$\left(1\right)$$ to get \begin{align*} \int_{0}^{2}\frac{1}{1-x^{3}}dx & =\frac{1}{3}h\left[y_{0}+4\sum_{i=1,3,5,\ldots}^{n-1}y_{i}+2\sum_{i=2,4,6,\ldots}^{n-1}y_{i}+y_{n}\right]\\ & =\frac{1}{3}h\left[y_{0}+4\left(y_{1}+y_{3}\right)+2\left(y_{2}\right)+y_{4}\right]\\ & =\frac{1}{3}\left(0.5\right)\left[1+4\left(0.888889+0.228571\right)\right.\\ & \quad\quad\left.+2\left(0.5\right)+0.111111.\right]\\ & =1.0968252\,. \end{align*} The answer, to five decimal places is, \begin{align*} \int_{0}^{2}\frac{1}{1-x^{3}}dx & =1.09683. \end{align*}

### Exercises

1. Use Simpson’s rule to evaluate the integral $$\int_{0}^{3}\left(3x^{2}+4x\right)dx$$ using 4 strips to two decimal places.

2. Use Simpson’s rule to evaluate the integral $$\int_{0}^{1}\left(3e^{x}\sin\left(x\right)\right)dx$$ using 2 strips to two decimal places.