Skip to main content

Math 220-2: Kursobjekt

Section 1.22 Numerical integration: techniques

Definition 1.22.1. Trapezoidal rule.

Let \(f\) be an integrable function on \([a,b]\text{,}\) let \(n\) be a positive integer, and let
\begin{equation*} a=x_0\lt x_1\lt x_2\lt \cdots \lt x_n=b \end{equation*}
be partition of \([a,b]\) into \(n\) subintervals of equal length \(\Delta x=\frac{b-a}{n}\text{.}\)
The \(n\)-th trapezoidal estimate of \(\displaystyle\int f(x)\, dx\text{,}\) denoted \(T_n\text{,}\) is defined as
\begin{equation*} T_n=\frac{1}{2}\Delta x(f(x_0)+2f(x_1)+2f(x_2)+\cdots +2f(x_{n-1})+f(x_n))\text{.} \end{equation*}
The trapezoidal estimate is the result of approximating the graph of \(f\) with the polygon passing through the points \(P_0=(x_0, f(x_0)), P_1=(x_1,f(x_1)), \dots, P_n=(x_n, f(x_n))\text{.}\)

Definition 1.22.2. Simpson’s rule.

Let \(f\) be an integrable function on \([a,b]\text{,}\) let \(n=2r\) be an even positive integer, and let
\begin{equation*} a=x_0\lt x_1\lt x_2\lt \cdots \lt x_n=b \end{equation*}
be partition of \([a,b]\) into \(n\) subintervals of equal length \(\Delta x=\frac{b-a}{n}\text{.}\)
The \(n\)-th Simpson’s rule estimate of \(\displaystyle\int f(x)\, dx\text{,}\) denoted \(S_n\text{,}\) is defined as
\begin{equation*} S_n=\frac{1}{3}\Delta x(f(x_0)+4f(x_1)+2f(x_2)+\cdots +2f(x_{n-2})+4f(x_{n-1})+f(x_n))\text{.} \end{equation*}
The Simpson’s rule estimate is the result of approximating the graph of \(f\) over each of the \(r\) subintervals \([x_{2(k-1)},x_{2k}]\) with the unique “parabolic arc” 1  passing through the points
\begin{equation*} P_{2(k-1)}=(x_{2(k-1)}, f(x_{2(k-1)})), P_{2k-1}=(x_{2k-1}, f(x_{2k-1})), P_{2k}=(x_{2k},f(x_{2k}))\text{.} \end{equation*}

Interactive example 1.22.1. Trapezoidal and Simpson’s rule.

Example 1.22.4. Estimating \(\ln 4\).

Let \(f(x)=\frac{1}{x}\text{.}\) Recall that we have by definition \(\ln 4=\int_1^4f(x)\, dx\text{.}\) Compute (a) the \(n=6\) trapezoidal estimate of \(I\text{,}\) and (b) the \(n=6\) Simpson’s rule estimate of \(I\text{.}\)
Solution.
In both cases, to estimate \(\ln 4=\int_1^4 \frac{1}{x}\, dx\) we partition the interval \([1,4]\) into six subintervals of length \(\Delta x=(4-1)/6=1/2\) as follows:
\begin{equation*} x_0=1< 3/2 < 2 < 5/2 < 3 < 7/2 < 4=x_6\text{.} \end{equation*}
  1. The \(n=6\) trapezoidal estimate is
    \begin{align*} T_6 \amp = \frac{1}{2}\Delta x(f(x_0)+2f(x_1)+\cdots +2f(x_5)+f(x_6))\\ \amp = \frac{1}{4}(1+2(2/3)+2(1/2)+2(2/5)+2(1/3)+2(2/7)+1/4)\\ \amp = \frac{2361}{1680}\\ \amp \approx 1.405 \end{align*}
  2. The \(n=6\) Simpson’s rule estimate is
    \begin{align*} S_6 \amp = \frac{1}{3}\Delta x(f(x_0)+4f(x_1)+2f(x_2)+4f(x_3)+2f(x_4)+4f(x_5)+f(x_6)) \\ \amp = \frac{1}{6}(1+4(2/3)+2(1/2)+4(2/5)+2(1/3)+4(2/7)+1/4)\\ \amp = \frac{3497}{2520}\\ \amp \approx 1.388 \end{align*}
The exact value of \(\int_1^4\frac{1}{x}\, dx\) is \(\ln 4\approx 1.3862946\dots\text{.}\)

Example 1.22.5. Estimating \(\pi\).

Let \(f(x)=\frac{4}{x^2+1}\text{,}\) and let \(I=\int_0^1f(x)\, dx\text{.}\)
  1. Show that \(I=\pi\text{.}\)
  2. Estimate \(\pi\) using the \(n=6\) trapezoidal estimate of \(I\text{.}\)
  3. Estimate \(\pi\) using the \(n=6\) Simpson’s rule estimate of \(I\text{.}\)
Solution.
First observe that we have
\begin{equation*} \int_0^1f(x)\, dx=\int_0^1\frac{4}{x^2+1}\, dx=4(\arctan 1-\arctan 0)=4(\pi/4-0)=\pi \text{.} \end{equation*}
For both estimates we partition the interval \([0,1]\) into six subintervals of length \(\Delta x=1/6\) as follows:
\begin{equation*} 0< 1/6 < 1/3 < 1/2 < 2/3 < 5/6 < 1\text{.} \end{equation*}
The \(n=6\) trapezoidal estimate \(T_6\) is then
\begin{align*} T_6 \amp = \frac{1}{2}\Delta x(f(0)+2f(1/6)+2f(1/3)+2f(1/2)+2f(2/3)+2f(5/6)+f(1))\\ \amp = \frac{1}{12}(4+288/37+\cdots + 288/61+2)\\ \amp = \frac{2,761,249}{880,230}\\ \amp \approx 3.1369\text{.} \end{align*}
Similarly, the \(n=6\) Simpson’s rule \(S_6\) estimate is
\begin{align*} S_6 \amp = \frac{1}{3}\cdot \frac{1}{6}(f(0)+4f(1/6)+2f(1/3)+4f(1/2)+2f(2/3)+4f(5/6)+f(1))\\ \amp = \frac{829, 597}{264,069}\\ \amp \approx 3.1416\text{.} \end{align*}
Compare these to the actual value of \(\pi\approx 3.141592653\dots\text{.}\)