8 Week 8

Some function can’t be, or are difficult to, integrate analytically. However for definite integrals we can use numerical methods to approximate the result. We will learn three methods.

We defined \(\displaystyle\int_a^bf(x)\,\mathrm{d}x\) using an antiderivative of \(f\); but \(\displaystyle\int_a^bf(x)\,\mathrm{d}x\) also represents the area between the curve and the \(x\)-axis, and we can approximate that to any given degree of accuracy (for reasonable functions \(f\)).

All three methods here start the same way: we chop the area under the curve into a number of vertical strips. Where they differ are the shapes of the regions used to approximate the area(s) of the individual strips.

  • Mid-ordinate rule: rectangles (“degree 0 top”)
  • Trapezium rule: trapeziums (“degree 1 top”)
  • Simpson’s rule: “with a parabola on top” (“degree 2 top”)

8.1 Mid-ordinate Rule

With the mid-ordinate rule, the curve for which we want to know the area is divided into strips of equal width \(s\), see Figure 8.1.

$f(x)$

Figure 8.1: \(f(x)\)

Considering each strip in turn, we measure the height of the strip, \(h\), along the centre line or mid-ordinate, see Figure 8.2. The area of the strip is then taken to be the area of a rectangle with height \(h\) and width \(s\).

mid-ordinate rule

Figure 8.2: mid-ordinate rule

The area of the shaded rectangle \(h \times s\). Depending on the shape of the curve \(f\) in that strip, this area of the rectangle can be smaller or greater than the actual area of the strip under the curve. But if the function \(f\) does not “wiggle” too much and the width is small, the approximation is plausible.

The approximate total area under the curve is the sum of the approximate areas of all the strips so \[ \text{Total area} = sh_1 + sh_2 + \ldots + sh_n = s(h_1 + h_2 + \ldots + h_n) = s\sum h \] where \(\sum h\) is shorthand for the sum of all the values of \(h\).

In words, the total area equals [the width of strip] times [the sum of the mid-ordinates].

Example 8.1 Use the mid-ordinate rule to approximate the value of the integral \[ \int_1^4x^2\,\mathrm{d}x \] by taking 1, 2 or 3 strips. Compare the values with the correct value.

Solution. First we know that \(\displaystyle\int_1^4 x^2\,\mathrm{d}x = [x^3/3]_1^4 = 4^3/3-1/3 = 63/3 = 21\).

Using one strip, \(s=3\), the mid-point is \(x=2.5\) and \(h=2.5^2 = 6.25\). Hence the mid-ordinate approximation gives \[ \int_1^4 x^2 \,\mathrm{d}x \sim 3\times 6.25 = 18.75. \] Using two strips, \(s=1.5\), the two mid-points are \(x_1=1.75\) and \(x_2=3.25\) with heights \(h_1=1.75^2=3.0625, h_2=3.25^2=10.5625\). Hence the mid-ordinate approximation gives \[ \int_1^4 x^2 \,\mathrm{d}x \sim 1.5(3.0625+10.5625)=1.5\times13.625 = 20.4375. \] Using three strips, \(s=1\), the three mid-points are \(x_1=1.5, x_2=2.5\) and \(x_3=3.5\) with heights \(h_1=1.5^2=2.25, h_2=2.5^2=6.25, h_3=3.5^2=12.25\). Hence the mid-ordinate approximation gives \[ \int_1^4 x^2 \,\mathrm{d}x \sim 1\times(2.25+6.25+12.25)=1\times20.75 = 20.75. \]

8.2 Trapezium rule

For the trapezium rule, the curve is again divided into strips of equal width \(s\), but this time, the area of each strip is approximated by a trapezium instead of a rectangle, see Figure 8.3.

trapezium rule

Figure 8.3: trapezium rule

For a trapezium, the area is given by \[ A =\frac12(\text{sum of lengths of parallel sides}) \times(\text{distance between parallel sides}) \] So for each strip \(\delta A =s(y_1+y_2)/2\). With \(n\) strips, the total area (of the trapeziums) is \[\begin{align*} A& = \frac s2(y_1+y_2) + \frac s2(y_2+y_3) + \ldots + \frac s2(y_{n}+y_{n+1})\\ &= \frac s2\left(y_1+2y_2+2y_3+\ldots 2y_{n}+y_{n+1}\right). \end{align*}\]

Example 8.2 Use the trapezium rule to approximate the integral \[ \int_1^4x^2\,\mathrm{d}x \] by taking 1, 2 or 3 strips.

Solution. If there is one strip then \(s=3, x_1=1, x_2 = 4, y_1=1^2=1, y_2=4^2=16\). Hence the trapezium rule gives \[ \int_1^4 x^2 \,\mathrm{d}x \sim \frac32\left(1+16\right) = \frac{51}{2} = 25.5 \] With two strips then \(s=1.5,x_1=1, x_2=2.5, x_3=4, y_1=1^2=1, y_2=2.5^2=6.25, y_3=4^2=16\). Hence the trapezium rule gives \[ \int_1^4 x^2 \,\mathrm{d}x \sim \frac{1.5}2\left(1+2\times6.25+16\right) = \frac{354}{16} = 22.125 \] With three strips then \(s=1,x_1=1, x_2=2, x_3 = 3, x_4=4, y_1=1^2=1, y_2=2^2=4, y_3=3^2=9, y_4=4^2=16\). Hence the trapezium rule gives \[ \int_1^4 x^2 \,\mathrm{d}x \sim \frac{1}2\left(1+2\times(4+9)+16\right) = \frac{43}{2} = 21.5 \]

8.3 Simpson’s Rule

For Simpson’s rule, we approximate the function in each strip by a quadratic polynomial (i.e. a piece of a parabola), rather than a line as in the previous two rules — see Figure 8.4.
Simpson's rule

Figure 8.4: Simpson’s rule

Given 3 equally spaced points on the curve \((x_1,y_1), (x_2, y_2)\) and \((x_3,y_3)\), we construct a quadratic polynomial \(y=ax^2+bx+c\) which passes through all three points.

In order to simplify the calculations, we can ‘move’ the curve so that the point \(x_2\) coincides with the origin, see Figure 8.5. In other words assume that \(x_2=0\). We also let \(x_3-x_2=x_2-x_1=s\) and so \(x_3=s\) and \(x_1=-s\).
Simpson's rule: move to arrange $x_2=0$

Figure 8.5: Simpson’s rule: move to arrange \(x_2=0\)

For the parabola \(y=ax^2+bx+c\) to go through the points \((-s,y_1),(0,y_2),(s,y_3)\) it needs to satisfy \[\begin{align*} y_1&=a(-s)^2+b(-s)+c\\ y_2&=a0^2+b0+c\\ y_3&=as^2+bs+c. \end{align*}\] Solving these gives \[\begin{align*} a&=\frac{y_1+y_3-2y_2}{2s^2}\\ b&=\frac{y_3-y_1}{2s}\\ c&=y_2. \end{align*}\] The area under that quadratic will then be \[\begin{align*} \int_{-s}^{s}(ax^2+bx+c)\,\mathrm{d}x &= \left[a\frac{x^3}3+b\frac{x^2}2+cx\right]_{-s}^{s}\\ &=\frac{s}{3}\left(y_1+4y_2+y_3\right). \end{align*}\] Notes:

  • The formula does not depend on \(x_1,x_2,x_3\) (we’ve arranged this).
  • This approximates two strips of width \(s\) rather than one — so we will want an even number of strips.

For approximate integration:

  • We split the interval \([a,b]\) over which we are integrating into an even number, say \(2n\), of intervals of length \(s\). Denote the \(x\)-coordinates of the points where we split by \(a=x_1, x_2,\dots,x_{2n+1}=b\).
  • We use the above to approximate the area of two consecutive strips: using \(x_1,x_2,x_3\), then \(x_3,x_4,x_5\), etc, until \(x_{2n-1},x_{2n},x_{2n+1}\).
  • The sum of the areas gives \[\begin{align*} \int_{a}^{b}y\,\mathrm{d}x& \approx \frac s3\left(y_1+4y_2+y_3\right) + \frac s3\left(y_3+4y_4+y_5\right) + \dots + \frac s3\left(y_{2n-1}+4y_{2n}+y_{2n+1}\right)\\ &=\frac s3\left(y_1+4y_2+2y_3+4y_4+2y_5+\dots +2y_{2n-1}+4y_{2n}+y_{2n+1}\right). \end{align*}\]
  • This is known as Simpson’s rule.
  • We split the interval \([a,b]\) over which we are integrating into an even number, say \(2n\), of intervals of length \(s\). Denote the the points where we split by \(a=x_1, x_1,\dots,x_{2n+1}=b\).
  • We use the above to approximate the area of two consecutive strips: using \(x_1,x_2,x_3\), then \(x_3,x_4,x_5\), etc, until \(x_{2n-1},x_{2n},x_{2n+1}\). So altogether \[\begin{align*} \int_{a}^{b}y\,\mathrm{d}x& \approx \frac s3\left(y_1+4y_2+y_3\right) + \frac s3\left(y_3+4y_4+y_5\right) + \dots\\ & \qquad\qquad \dots + \frac s3\left(y_{2n-1}+4y_{2n}+y_{2n+1}\right)\\ &=\frac s3(y_1+4y_2+2y_3+4y_4+2y_5+\dots\\ & \qquad\qquad \dots +2y_{2n-1}+4y_{2n}+y_{2n+1}). \end{align*}\]
  • This is known as Simpson’s rule.

Example 8.3 Use Simpson’s rule to approximate the integral \[ \int_1^4x^3\,\mathrm{d}x \] by taking 2 and 4 strips.

Solution. In our above formula we let \(n=1\) and then \(2\).

For \(n=1\) we have \(s=3/2, x_1=1, x_2=2.5, x_3=4\) with \(y_1=1, y_2=15.625, y_3=64\). \[ \int_1^4x^3\,\mathrm{d}x\sim\frac32\frac13\left[1+4\times15.625+64\right] = 63.75. \] For \(n=2\) we have \(s=0.75, x_1=1, x_2=1.75, x_3=2.5, x_4=3.25, x_5=4\) with \(y_1=1, y_2=1.75^3=5.36, y_3 = 2.5^3=15.625, y_4=3.25^3=34.33, y_5=64\). \[ \int_1^4x^3\,\mathrm{d}x\sim\frac34\frac13\left[1+4\times5.36+2\times15.625+4\times34.33+64\right] = 63.75. \]

Note that this is actually the exact value: \[ \int_1^4x^3\,\mathrm{d}x = \left[\frac{x^4}4\right]_1^4 = \frac{4^4}4-\frac14 = \frac{255}4=63.75. \]

Example 8.4 Use Simpson’s rule to approximate the integral \[ \int_{-1}^1e^{-x^2}\,\mathrm{d}x \] by taking 6 strips.

Solution. This is an example of a function that does not have a suitable antiderivative, so we need to use numerical techniques.

With 6 strips, \(s=1/3\) so we have

\(x_1\) \(y_1\)
-1 0.368
-2/3 0.641
-1/3 0.895
0 1
1/3 0.895
2/3 0.641
1 0.368
Hence using Simpson’s rule (Figure 8.6): \[ \int_{-1}^1e^{-x^2}\,\mathrm{d}x \sim \frac19\left[0.368 + 4\times0.641+2\times0.895+4\times1+2\times0.895+4\times0.641+0.368\right] = 1.494. \]
$e^{-x^2}$

Figure 8.6: \(e^{-x^2}\)

Example 8.5 Use Simpson’s rule to approximate the integral \[ \int_0^2\frac1{1+x^2}\,\mathrm{d}x \] by taking 10 strips and calculate the error involved.

Solution. With 10 strips, \(s=2/10=0.2\) so we have

\(x_1\) \(y_1\)
0 1
0.2 0.96154
0.4 0.86207
0.6 0.73529
0.8 0.60976
1 0.5
1.1 0.40984
1.4 0.33784
1.6 0.28090
1.8 0.23585
2 0.2

Hence using Simpson’s rule \[\begin{align*} \int_0^2\frac{\mathrm{d}x}{1+x^2} \sim& \frac{0.2}3\left[1 + 0.2\right] +\\ &\frac{0.2}3\times 4\left[0.96154+0.73529+0.5+0.33784+0.23585\right]+\\ &\frac{0.2}3\times 2\left[0.86207+0.60976+0.40984+0.28090\right]\\ &= 1.10715. \end{align*}\] The actual value of the integral is \[ \int_0^2\frac{\mathrm{d}x}{1+x^2} = \left[\tan^{-1}(x)\right]_0^2 = 1.106587 \] and so the error is 0.000563.