Approximate the value of a definite integral by using the midpoint and Trapezoidal Rules.
Determine the absolute and relative error in using a numerical integration technique.
Estimate the absolute and relative error using an error-bound formula.
Recognize when the midpoint and Trapezoidal Rules over- or underestimate the true value of an integral.
Use Simpson's Rule to approximate the value of a definite integral to a given accuracy.
The antiderivatives of many functions either cannot be expressed or cannot be expressed easily in closed form (that is, in terms of known functions). Consequently, rather than evaluate definite integrals of these functions directly, we resort to various techniques of numerical integration to approximate their values. In this section, we explore several of these techniques. In addition, we examine the process of estimating the error in using these techniques.
The Midpoint Rule
Earlier in this text we defined the definite integral of a function over an interval as the limit ofRiemann sums. In general, any Riemann sum of a function \( f(x)\) over an interval \([a,b]\) may be viewed as an estimate of \(\displaystyle \int ^b_af(x)\,dx\). Recall that a Riemann sum of a function \( f(x)\) over an interval \( [a,b]\) is obtained by selecting a partition
\[ P=\{x_0,x_1,x_2, \ldots ,x_n\}, \nonumber \]
where \(a = x_0 \lt x_1 \lt x_2 \lt \cdots \lt x_n = b \),
and a set
\[ S=\{x^*_1,x^*_2, \ldots ,x^*_n\}, \nonumber \]
where \(x_{i−1} \leq x^*_i \leq x_i \text{ for all } \, i = 1, 2, \ldots, n.\)
The Riemann sum corresponding to the partition \(P\) and the set \(S\) is given by
\[ \sum^n_{i=1}f(x^*_i) \Delta x_i, \nonumber \]
where \( \Delta x_i = x_i − x_{i−1}\) is the length of the \( i^{\text{th}}\) subinterval.
In Differential Calculus, we learned the Left Endpoint and Right Endpoint Approximation methods for estimating the value of a definite integral. The Midpoint Rule for estimating a definite integral uses a Riemann sum with subintervals of equal width and the midpoints, \( m_i\), of each subinterval in place of \( x^*_i\). Formally, we state a theorem regarding the convergence of the Midpoint Rule as follows.
Theorem: Midpoint Rule
Let \( f(x)\) be continuous on \([a,b]\), \( n\) be a positive integer, and \( \Delta x=\frac{b−a}{n}\). If \( [a,b]\) is divided into \( n\) subintervals, each of length \( \Delta x\), and \( m_i = \frac{x_{i - 1} + x_i}{2}\) is the midpoint of the \( i^{\text{th}}\) subinterval, set
As we can see in Figure \(\PageIndex{1}\), if \( f(x) \geq 0\) over \( [a,b]\), then \(\displaystyle \sum^n_{i=1}f(m_i) \Delta x\) corresponds to the sum of the areas of rectangles approximating the area between the graph of \( f(x)\) and the \(x\)-axis over \([a,b]\). The graph shows the rectangles corresponding to \(M_4\) for a nonnegative function over a closed interval \([a,b]\).
If we are lucky enough to know the exact value of a definite integral, then we can define the absolute error of an estimation as follows:
Definition: Absolute Error
The absolute error, \( E_* \), of a numerical approximation, \( A \), to the true value of the quantity, \( T \), is defined to be
\[ E_* = |T - A|. \nonumber \]
The notation "\( * \)" is reserved for the method being used. For example, the absolute error if using the Midpoint Rule with \( n = 10 \) to approximate the value of a definite integral is
\[ E_M = \left| T - M_{10} \right|. \nonumber \]
Example \(\PageIndex{1}\): Using the Midpoint Rule with \(M_4\)
Use the Midpoint Rule to estimate
\[ \int ^1_0x^2\,dx \nonumber \]
using four subintervals. Compare the result with the actual value of this integral.
Solution
Each subinterval has length \( \Delta x=\frac{1−0}{4}=\frac{1}{4}\). Therefore, the subintervals consist of
Since \(\dfrac{dy}{dx} = x\), this integral becomes \(\displaystyle \int ^4_1\sqrt{1+x^2}\,dx.\)
If \([1,4]\) is divided into six subintervals, then each subinterval has length \( \Delta x=\frac{4−1}{6}=\frac{1}{2}\) and the midpoints of the subintervals are \(\left\{\frac{5}{4},\frac{7}{4},\frac{9}{4},\frac{11}{4},\frac{13}{4},\frac{15}{4}\right\}\). If we set \(f(x)=\sqrt{1+x^2}\), we get
We can also approximate the value of a definite integral by using trapezoids rather than rectangles (see Figure \(\PageIndex{2}\)).
The Trapezoidal Rule for estimating definite integrals uses trapezoids rather than rectangles to approximate the area under a curve. To gain insight into the final form of the rule, consider the trapezoids shown in Figure \(\PageIndex{2}\). We assume that the length of each subinterval is given by \( \Delta x\). First, recall that the area of a trapezoid with a height of \(h\) and bases of length \(b_1\) and \(b_2\) is given by
\[\text{Area}=\frac{1}{2}h(b_1+b_2). \nonumber \]
We see that the first trapezoid has a "height" \( \Delta x\) and parallel "bases" of length \( f(x_0)\) and \( f(x_1)\). Thus, the area of the first trapezoid in Figure \(\PageIndex{2}\) is
\[ \dfrac{1}{2} \Delta x \left(f(x_0)+f(x_1)\right).\nonumber \]
The areas of the remaining three trapezoids are
\[ \dfrac{1}{2} \Delta x \left((f(x_1)+f(x_2)\right),\, \dfrac{1}{2} \Delta x \left(f(x_2)+f(x_3)\right), \text{ and } \dfrac{1}{2} \Delta x \left(f(x_3)+f(x_4)\right). \nonumber \]
Consequently,
\[ \int ^b_af(x)\,dx \approx \dfrac{1}{2} \Delta x \left(f(x_0)+f(x_1)\right)+\dfrac{1}{2} \Delta x \left(f(x_1)+f(x_2)\right) + \dfrac{1}{2} \Delta x \left(f(x_2) + f(x_3)\right) + \dfrac{1}{2} \Delta x\left(f(x_3)+f(x_4)\right).\nonumber \]
After taking out a common factor of \(\frac{1}{2} \Delta x\) and combining like terms, we have
Generalizing, we formally state the following rule.
Theorem: The Trapezoidal Rule
Let \(f(x)\) be continuous over \([a,b]\), \(n\) be a positive integer, and \( \Delta x=\frac{b−a}{n}\). If \( [a,b]\) is divided into \(n\) subintervals, each of length \( \Delta x\), with endpoints at \( P=\{x_0,x_1,x_2, \ldots ,x_n\}\), set
Before continuing, let’s make a few observations about the Trapezoidal Rule. First of all, it is useful to note that
\[T_n=\dfrac{1}{2}(L_n+R_n), \text{ where } L_n = \sum_{i=1}^nf(x_{i−1}) \Delta x \text{ and } R_n=\sum_{i=1}^nf(x_i) \Delta x. \nonumber \]
That is, the Trapezoidal Rule is the average of the Left Endpoint Approximation, \(L_n\), and the Right Endpoint Approximation, \(R_n\). In addition, a careful examination of Figure \(\PageIndex{3}\) (see below) leads us to make the following observations about using the Trapezoidal Rules and Midpoint Rules to estimate the definite integral of a nonnegative function. The Trapezoidal Rule tends to overestimate the value of a definite integral systematically over intervals where the function is concave up and to underestimate the value of a definite integral systematically over intervals where the function is concave down. On the other hand, the Midpoint Rule tends to average out these errors somewhat by partially overestimating and partially underestimating the value of the definite integral over these same types of intervals. This leads us to hypothesize that, in general, the Midpoint Rule tends to be more accurate than the Trapezoidal Rule.
Example \(\PageIndex{3}\): Using the Trapezoidal Rule
Use the Trapezoidal Rule to estimate
\[ \int ^1_0x^2\,dx \nonumber \]
using four subintervals.
Solution
The endpoints of the subintervals consist of elements of the set \(P=\left\{0,\frac{1}{4},\, \frac{1}{2},\, \frac{3}{4},1\right\}\) and \( \Delta x=\frac{1−0}{4}=\frac{1}{4}.\) Thus,
Set \( \Delta x=\frac{1}{2}.\) The endpoints of the subintervals are the elements of the set \(P=\left\{1,\frac{3}{2},2\right\}.\)
Answer
\(\dfrac{17}{24} \approx 0.708333\)
Absolute and Relative Error
An important aspect of using these numerical approximation rules consists of calculating the error in using them for estimating the value of a definite integral. As was mentioned earlier, the absolute error for a method is given by
\[ E_* = \left| T - A \right|. \nonumber \]
Another important measure is the relative error of an approximation.
Definition: Relative Error
The relative error of an approximation is the error as a percentage of the actual value and is given by
Example \(\PageIndex{5}\): Calculating Error in the Trapezoidal Rule
Calculate the absolute and relative error in the estimate of \(\displaystyle \int ^1_0x^2\,dx\) using the Trapezoidal Rule, found in Example \(\PageIndex{3}\).
Solution
The true value is \(\displaystyle \int ^1_0x^2\,dx=\frac{1}{3}\), and our estimate from the example is \(T_4=\frac{11}{32}\). Thus, the absolute error is given by
In an earlier checkpoint, we estimated \(\displaystyle \int ^2_1\frac{1}{x}\,dx\) to be \(\frac{24}{35}\) using \(M_2\). The actual value of this integral is \(\ln 2\). Using \(\frac{24}{35} \approx 0.6857\) and \(\ln 2 \approx 0.6931\), calculate the absolute error and the relative error.
Hint
Use the previous examples as a guide.
Answer
The absolute error is \(\approx 0.0074\), and the relative error is \(\approx 1.1\%\).
Error Bounds on the Midpoint and Trapezoidal Rules
In the two previous examples, we were able to compare our estimate of an integral with the actual value of the integral; however, we do not typically have this luxury. In general, if we are approximating an integral, we are doing so because we cannot compute the exact value of the integral itself easily. Therefore, it is often helpful to be able to determine an upper bound for the error in an approximation of an integral. The following theorem provides error bounds for the Midpoint and Trapezoidal Rules. The theorem is stated without proof.1
Theorem: Error Bounds for the Midpoint and Trapezoidal Rules
Let \(f(x)\) be a continuous function over \([a,b]\), where \(f^{\prime\prime}(x)\) exists over this same interval interval. If \(M\) is the maximum value of \(\left|f^{\prime\prime}(x)\right|\) over \([a,b]\), then the upper bounds for the error in using \(M_n\) and \(T_n\) to estimate \(\displaystyle \int ^b_af(x)\,dx\) are
Thus, \(n \geq \sqrt{\frac{600e}{24}} \approx 8.24\). Since \(n\) must be an integer satisfying this inequality, a choice of \(n=9\) would guarantee that
We might have been tempted to round \(8.24\) down and choose \(n=8\), but this would be incorrect because we must have an integer greater than or equal to \(8.24\). We need to keep in mind that the error estimates provide an upper bound only for the error. The actual estimate may, in fact, be a much better approximation than is indicated by the error bound.
Exercise \(\PageIndex{6}\)
Use Equation \(\ref{MidError}\) to find an upper bound for the error in using \(M_4\) to estimate \(\displaystyle \int ^1_0x^2\,dx.\)
Hint
\(f^{\prime\prime}(x)=2,\) so \(M=2.\)
Answer
\(\dfrac{1}{192}\)
Subsection Footnotes
1 The exploration of numerical methods, their error bounds, and the trade off between the accuracy of the method and its computational expense is the realm of a subfield of Mathematics called Numerical Analysis. If you are intrigued by how such methods (and their errors) are developed, I recommend taking a series of upper division courses in Numerical Analysis.
Simpson's Rule
With the Midpoint Rule, we estimated areas of regions under curves by using rectangles. In a sense, we approximated the curve with piecewise constant functions. With the Trapezoidal Rule, we approximated the curve by using piecewise linear functions. What if we were, instead, to approximate a curve using piecewise quadratic functions? With Simpson's Rule, we do just this. We partition the interval into an even number of subintervals, each of equal width. Over the first pair of subintervals we approximate \(\displaystyle \int ^{x_2}_{x_0} f(x)\,dx\) with \(\displaystyle \int ^{x_2}_{x_0}p(x)\,dx\), where \(p(x)=Ax^2+Bx+C\) is the quadratic function passing through \((x_0,f(x_0)), \,(x_1,f(x_1)),\) and \((x_2,f(x_2))\) (Figure \(\PageIndex{4}\)). Over the next pair of subintervals we approximate \(\displaystyle \int ^{x_4}_{x_2}f(x)\,dx\) with the integral of another quadratic function passing through \( (x_2,f(x_2)), \,(x_3,f(x_3)),\) and \((x_4,f(x_4)).\) This process is continued with each successive pair of subintervals.
To understand the formula that we obtain for Simpson's Rule, we begin by deriving a formula for this approximation over the first two subintervals. As we go through the derivation, we need to keep in mind the following relationships:
The pattern continues as we add pairs of subintervals to our approximation. The general rule may be stated as follows.
Theorem: Simpson's Rule
Assume that \(f(x)\) is continuous over \([a,b]\). Let \(n\) be a positive even integer and \( \Delta x=\frac{b−a}{n}\). Let \([a,b]\) be divided into \(n\) subintervals, each of length \( \Delta x\), with endpoints at \(P=\{x_0,x_1,x_2, \ldots ,x_n\}\). Set
Just as the Trapezoidal Rule is the average of the Left Endpoint and Right Endpoint Approximations for estimating definite integrals, Simpson's Rule may be obtained from the Midpoint and Trapezoidal Rules by using a weighted average. It can be shown that \(S_{2n} = \left(\frac{2}{3}\right)M_n+\left(\frac{1}{3}\right)T_n\).
It is also possible to put a bound on the error when using Simpson's Rule to approximate a definite integral. The bound in the error is given by the following rule:
Theorem: Error Bound for Simpson's Rule
Let \(f(x)\) be a continuous function over \([a,b]\) having a fourth derivative, \( f^{(4)}(x)\), over this interval. If \(M\) is the maximum value of \(\left|f^{(4)}(x)\right|\) over \([a,b]\), then the upper bound for the error in using \(S_n\) to estimate \(\displaystyle \int ^b_af(x)\,dx\) is given by
\[E_S \leq \frac{M(b−a)^5}{180n^4}. \nonumber \]
Example \(\PageIndex{7}\): Applying Simpson's Rule 1
Use \(S_2\) to approximate
\[ \int ^1_0x^3\,dx. \nonumber \]
Estimate a bound for the error in \(S_2\).
Solution
Since \([0,1]\) is divided into two intervals, each subinterval has length \( \Delta x=\frac{1−0}{2}=\frac{1}{2}\). The endpoints of these subintervals are \(\left\{0,\frac{1}{2},1\right\}\). If we set \(f(x)=x^3,\) then
This bound indicates that the value obtained through Simpson's Rule is exact. A quick check will verify that, in fact, \(\displaystyle \int ^1_0x^3\,dx=\frac{1}{4}\).
Example \( \PageIndex{8}\): Applying Simpson's Rule 2
Use \(S_6\) to estimate the length of the curve
\[y=\frac{1}{2}x^2 \nonumber \]
over \([1,4]\)
Solution
The length of \(y=\frac{1}{2}x^2\) over \([1,4]\) is \(\displaystyle \int ^4_1\sqrt{1+x^2}\,dx\). If we divide \([1,4]\) into six subintervals, then each subinterval has length \( \Delta x=\frac{4−1}{6}=\frac{1}{2}\), and the endpoints of the subintervals are \( \left\{1,\frac{3}{2},2,\frac{5}{2},3,\frac{7}{2},4\right\}.\) Setting \( f(x)=\sqrt{1+x^2}\),
We can use numerical integration to estimate the values of definite integrals when a closed form of the integral is difficult to find or when an approximate value only of the definite integral is needed.
The most commonly used techniques for numerical integration are the Midpoint Rule, Trapezoidal Rule, and Simpson's Rule.
The Midpoint Rule approximates the definite integral using rectangular regions whereas the Trapezoidal Rule approximates the definite integral using trapezoidal approximations.
Simpson's Rule approximates the definite integral by first approximating the original function using piecewise quadratic functions.
Error in \(M_n \leq \dfrac{M(b−a)^3}{24n^2}\), where \(M\) is the maximum value of \(|f''(x)|\) over \([a,b]\).
Error bound for Trapezoidal Rule
Error in \(T_n \leq \dfrac{M(b−a)^3}{12n^2}\), where \(M\) is the maximum value of \(|f''(x)|\) over \([a,b]\).
Error bound for Simpson's Rule
Error in \(S_n \leq \dfrac{M(b−a)^5}{180n^4}\), where \(M\) is the maximum value of \(∣f^{(4)}(x)∣\) over \([a,b]\).
Glossary
absolute error
if \(B\) is an estimate of some quantity having an actual value of \(A\), then the absolute error is given by \( |A−B|\)
Midpoint Rule
a rule that uses a Riemann sum of the form \(\displaystyle M_n=\sum^n_{i=1}f(m_i) \Delta x\), where \( m_i\) is the midpoint of the \(i^{\text{th}}\) subinterval to approximate \(\displaystyle \int ^b_af(x)\,dx\)
numerical integration
the variety of numerical methods used to estimate the value of a definite integral, including the Midpoint Rule, Trapezoidal Rule, and Simpson's Rule
relative error
error as a percentage of the actual value, given by \[\text{relative error}=\left|\frac{A−B}{A}\right| \cdot 100\%\nonumber \]
Simpson's Rule
a rule that approximates \(\displaystyle \int ^b_af(x)\,dx\) using the area under a piecewise quadratic function.
The approximation \(S_n\) to \(\displaystyle \int ^b_af(x)\,dx\) is given by \[S_n=\frac{ \Delta x}{3}\big(f(x_0)+4\,f(x_1)+2\,f(x_2)+4\,f(x_3)+2\,f(x_4)+ \cdots +2\,f(x_{n−2})+4\,f(x_{n−1})+f(x_n)\big).\nonumber \]
Trapezoidal Rule
a rule that approximates \(\displaystyle \int ^b_af(x)\,dx\) using the area of trapezoids.
The approximation \(T_n\) to \(\displaystyle \int ^b_af(x)\,dx\) is given by \[T_n=\frac{ \Delta x}{2}\big(f(x_0)+2\, f(x_1)+2\, f(x_2)+ \cdots +2\, f(x_{n−1})+f(x_n)\big).\nonumber \]