Skip to main content

Subsection 1.11.1 The midpoint rule

The integral \(\int_{x_{j-1}}^{x_j} f(x)\,\dee{x}\) represents the area between the curve \(y=f(x)\) and the \(x\)-axis with \(x\) running from \(x_{j-1}\) to \(x_j\text{.}\) The width of this region is \(x_j-x_{j-1}=\De x\text{.}\) The height varies over the different values that \(f(x)\) takes as \(x\) runs from \(x_{j-1}\) to \(x_j\text{.}\)

The midpoint rule approximates this area by the area of a rectangle of width \(x_j-x_{j-1}=\De x\) and height \(f(\bar x_j)\) which is the exact height at the midpoint of the range covered by \(x\text{.}\)

The area of the approximating rectangle is \(f(\bar x_j)\De x\text{,}\) and the midpoint rule approximates each subintegral by

\begin{equation*} \int_{x_{j-1}}^{x_j} f(x)\,\dee{x}\approx f(\bar x_j)\De x\text{.} \end{equation*}

Applying this approximation to each subinterval and summing gives us the following approximation of the full integral:

\begin{align*} \int_a^b f(x)\,\dee{x}&= \int_{x_0}^{x_1}\!\! f(x)\,\dee{x} + \int_{x_1}^{x_2}\!\! f(x)\,\dee{x} +\cdots + \int_{x_{n-1}}^{x_n} f(x)\,\dee{x}\\ &\approx f(\bar x_1)\De x + f(\bar x_2)\De x + \cdots + f(\bar x_n)\De x \end{align*}

So notice that the approximation is the sum of the function evaluated at the midpoint of each interval and then multiplied by \(\De x\text{.}\) Our other approximations will have similar forms.

In summary:

We approximate the above integral using the midpoint rule with \(n=8\) step.

Solution:

  • First we set up all the \(x\)-values that we will need. Note that \(a=0\text{,}\) \(b=1\text{,}\) \(\De x=\tfrac{1}{8}\) and
    \begin{align*} x_0&=0 & x_1&=\tfrac{1}{8} & x_2&=\tfrac{2}{8} && \cdots & x_7&=\tfrac{7}{8}& x_8&=\tfrac{8}{8}=1 \end{align*}
    Consequently
    \begin{align*} \bar x_1&= \tfrac{1}{16} & \bar x_2&= \tfrac{3}{16} & \bar x_3&= \tfrac{5}{16} & \cdots&& \bar x_8 &= \tfrac{15}{16} \end{align*}
  • We now apply Equation 1.11.2 to the integrand \(f(x)=\frac{4}{1+x^2}\text{:}\)
    \begin{align*} &\int_0^1 \frac{4}{1+x^2}\,\dee{x} \approx \bigg[\overbrace{\frac{4}{1+\bar x_1^2}}^{f(\bar x_1)} +\overbrace{\frac{4}{1+\bar x_2^2}}^{f(\bar x_2)} +\!\cdots\! +\overbrace{\frac{4}{1+\bar x_7^2}}^{f(\bar x_{n-1})} +\overbrace{\frac{4}{1+\bar x_8^2}}^{f(\bar x_n)} \bigg]\De x\\ &=\bigg[\frac{4}{1+\tfrac{1}{16^2}}+ \frac{4}{1+\tfrac{3^2}{16^2}}+ \frac{4}{1+\tfrac{5^2}{16^2}}+ \frac{4}{1+\tfrac{7^2}{16^2}} +\frac{4}{1+\tfrac{9^2}{16^2}}\\ &\hskip2in +\frac{4}{1+\tfrac{11^2}{16^2}}+ \frac{4}{1+\tfrac{13^2}{16^2}}+ \frac{4}{1+\tfrac{15^2}{16^2}}\bigg]\frac{1}{8}\\ &=\big[ 3.98444 + 3.86415 + 3.64413 + 3.35738 + 3.03858 +\\ &\hskip2in 2.71618 + 2.40941 + 2.12890 \big]\frac{1}{8}\\ &= 3.1429 \end{align*}
    where we have rounded to four decimal places.
  • In this case we can compute the integral exactly (which is one of the reasons it was chosen as a first example):
    \begin{gather*} \int_0^1\frac{4}{1+x^2}\dee{x} =4\arctan x\Big|_0^1 = \pi \end{gather*}
  • So the error in the approximation generated by eight steps of the midpoint rule is
    \begin{align*} |3.1429-\pi| &=0.0013 \end{align*}
  • The relative error is then
    \begin{align*} \frac{|\text{approximate}-\text{exact}|}{\text{exact}} &= \frac{|3.1429-\pi|}{\pi}=0.0004 \end{align*}
    That is the error is \(0.0004\) times the actual value of the integral.
  • We can write this as a percentage error by multiplying it by 100
    \begin{align*} \text{percentage error} &= 100 \times \frac{|\text{approximate}-\text{exact}|}{\text{exact}} = 0.04 \% \end{align*}
    That is, the error is about \(0.04\%\) of the exact value.

The midpoint rule gives us quite good estimates of the integral without too much work — though it is perhaps a little tedious to do by hand  2 Thankfully it is very easy to write a program to apply the midpoint rule.. Of course, it would be very helpful to quantify what we mean by “good” in this context and that requires us to discuss errors.

Definition 1.11.4

Suppose that \(\alpha\) is an approximation to \(A\text{.}\) This approximation has

  • absolute error \(|A-\alpha|\) and
  • relative error \(\frac{|A-\alpha|}{|A|}\) and
  • percentage error \(100\frac{|A-\alpha|}{|A|}\)

We will discuss errors further in Section 1.11.4 below.

As a second example, we apply the midpoint rule with \(n=8\) steps to the above integral.

  • We again start by setting up all the \(x\)-values that we will need. So \(a=0\text{,}\) \(b=\pi\text{,}\) \(\De x=\tfrac{\pi}{8}\) and
    \begin{align*} x_0&=0& x_1&=\tfrac{\pi}{8}& x_2&=\tfrac{2\pi}{8}& \cdots&& x_7&=\tfrac{7\pi}{8}& x_8&=\tfrac{8\pi}{8}=\pi \end{align*}
    Consequently,
    \begin{align*} \bar x_1&=\tfrac{\pi}{16}& \bar x_2&=\tfrac{3\pi}{16} & \cdots&& \bar x_7&=\tfrac{13\pi}{16} & \bar x_8&=\tfrac{15\pi}{16} \end{align*}
  • Now apply Equation 1.11.2 to the integrand \(f(x)=\sin x\text{:}\)
    \begin{align*} &\int_0^\pi\sin x\,\dee{x} \approx\Big[\sin(\bar x_1)+\sin(\bar x_2)+\cdots+\sin(\bar x_8)\Big]\De x\\ &=\Big[\sin(\tfrac{\pi}{16})+ \sin(\tfrac{3\pi}{16})+ \sin(\tfrac{5\pi}{16})+ \sin(\tfrac{7\pi}{16})+ \sin(\tfrac{9\pi}{16})+\\ &\hskip2in \sin(\tfrac{11\pi}{16})+ \sin(\tfrac{13\pi}{16})+ \sin(\tfrac{15\pi}{16})\Big]\tfrac{\pi}{8}\\ &=\Big[0.1951+ 0.5556+ 0.8315+ 0.9808+ 0.9808+\\ &\hskip2in 0.8315+ 0.5556+ 0.1951\Big]\times 0.3927\\ &=5.1260\times 0.3927 =2.013 \end{align*}
  • Again, we have chosen this example so that we can compare it against the exact value:
    \begin{align*} \int_0^\pi \sin x \dee{x} &= \big[ -\cos x \big]_0^\pi = -\cos\pi + \cos 0 = 2. \end{align*}
  • So with eight steps of the midpoint rule we achieved
    \begin{align*} \text{absolute error} &= |2.013-2|=0.013\\ \text{relative error} &= \frac{|2.013-2|}{2} = 0.0065\\ \text{percentage error} &= 100 \times \frac{|2.013-2|}{2} = 0.65 \% \end{align*}
    With little work we have managed to estimate the integral to within \(1\%\) of its true value.