Skip to main content
Logo image

APEX Calculus

Section 5.5 Numerical Integration

The Fundamental Theorem of Calculus gives a concrete technique for finding the exact value of a definite integral. That technique is based on computing antiderivatives. Despite the power of this theorem, there are still situations where we must approximate the value of the definite integral instead of finding its exact value. The first situation we explore is where we cannot compute the antiderivative of the integrand. The second case is when we actually do not know the function in the integrand, but only its value when evaluated at certain points.
An elementary function is any function that is a combination of polynomial, \(n\)th root, rational, exponential, logarithmic and trigonometric functions. We can compute the derivative of any elementary function, but there are many elementary functions of which we cannot compute an antiderivative. For example, the following functions do not have antiderivatives that we can express with elementary functions:
  • \(e^{x^2}\text{,}\)
  • \(\sin(x^3)\text{,}\)
  • \(\frac{\sin(x)}{x}\text{.}\)
The simplest way to refer to the antiderivatives of \(e^{-x^2}\) is to simply write \(\int e^{-x^2}\, dx\text{.}\)
This section outlines three common methods of approximating the value of definite integrals. We describe each as a systematic method of approximating area under a curve. By approximating this area accurately, we find an accurate approximation of the corresponding definite integral.
We will apply the methods we learn in this section to the following definite integrals:
  • \(\int_0^1 e^{-x^2} \, dx\text{,}\)
  • \(\int_{-\frac{\pi}{4}}^{\frac{\pi}{2}} \sin(x^3) \, dx\text{,}\)
  • \(\int_{0.5}^{4\pi} \frac{\sin(x)}{x} \, dx\text{,}\)
as pictured in Figure 5.5.1.
(a)
(b)
(c)
Figure 5.5.1. Graphically representing three definite integrals that cannot be evaluated using antiderivatives

Subsection 5.5.1 The Left and Right Hand Rule Methods

In Section 5.3 we addressed the problem of evaluating definite integrals by approximating the area under the curve using rectangles. We revisit those ideas here before introducing other methods of approximating definite integrals.
We start with a review of notation. Let \(f\) be a continuous function on the interval \([a,b]\text{.}\) We wish to approximate \(\ds \int_a^b f(x)\, dx\text{.}\) We partition \([a,b]\) into \(n\) equally spaced subintervals, each of length \(\ds\dx = \frac{b-a}{n}\text{.}\) The endpoints of these subintervals are labeled as
\begin{equation*} x_0=a,\,x_1 = a+\dx,\,x_2 = a+ 2\dx,\,\ldots,\,x_i = a+i\dx,\,\ldots,\,x_{n} = b\text{.} \end{equation*}
Key Idea 5.3.20 states that to use the Left Hand Rule we use the summation \(\ds \sum_{i=1}^n f(x_{i-1})\dx\) and to use the Right Hand Rule we use \(\ds \sum_{i=1}^n f(x_{i})\dx\text{.}\) We review the use of these rules in the context of examples.

Example 5.5.2. Approximating definite integrals with rectangles.

Approximate \(\ds \int_0^1e^{-x^2}\, dx\) using the Left and Right Hand Rules with 5 equally spaced subintervals.
Solution.
We begin by partitioning the interval \([0,1]\) into 5 equally spaced intervals. We have \(\dx = \frac{1-0}5 = 1/5=0.2\text{,}\) so
\begin{equation*} x_0 = 0,\,x_1 = 0.2,\,x_2 = 0.4,\,x_3 = 0.6,\,x_4 = 0.8,\,\text{ and } \,x_5 = 1\text{.} \end{equation*}
Using the Left Hand Rule, we have:
\begin{align*} \sum_{i=1}^n f(x_{i-1})\dx \amp = \big(f(x_0)+f(x_1) + f(x_2) + f(x_3) + f(x_4)\big)\dx\\ \amp = \big(f(0) + f(0.2) + f(0.4) + f(0.6) + f(0.8)\big)\dx\\ \amp \approx (1+0.9608 +0.8521 + 0.6977 + 0.5273)(0.2)\\ \amp \approx 0.8076\text{.} \end{align*}
Using the Right Hand Rule, we have:
\begin{align*} \sum_{i=1}^n f(x_{i})\dx \amp = \big(f(x_1) + f(x_2) + f(x_3) + f(x_4)+f(x_5)\big)\dx\\ \amp = \big(f(0.2) + f(0.4) + f(0.6) + f(0.8)+f(1)\big)\dx\\ \amp \approx (0.9608 +0.8521 + 0.6977 + 0.5273 + 0.3678)(0.2)\\ \amp \approx 0.6812\text{.} \end{align*}
(a) Using the Left Hand Rule
(b) Using the Right Hand Rule
Figure 5.5.3. Approximating \(\int_0^1e^{-x^2}\, dx\) in Example 5.5.2
Figure 5.5.3 shows the rectangles used in each method to approximate the definite integral. These graphs show that in this particular case, the Left Hand Rule is an over approximation and the Right Hand Rule is an under approximation. To get a better approximation, we could use more rectangles, as we did in Section 5.3. We could also average the Left and Right Hand Rule results together, giving
\begin{equation*} \frac{0.8076 + 0.6812}{2} = 0.7444\text{.} \end{equation*}
The actual answer, accurate to 4 places after the decimal, is 0.7468, showing our average is a good approximation.

Example 5.5.4. Approximating definite integrals with rectangles.

Approximate \(\ds\int_{-\frac{\pi}4}^{\frac{\pi}2} \sin(x^3)\, dx\) using the Left and Right Hand Rules with 10 equally spaced subintervals.
Solution.
We begin by finding \(\dx\text{:}\)
\begin{equation*} \frac{b-a}{n} = \frac{\pi/2 - (-\pi/4)}{10} = \frac{3\pi}{40}\approx 0.2356\text{.} \end{equation*}
It is useful to write out the endpoints of the subintervals in a table; in Figure 5.5.5, we give the exact values of the endpoints, their decimal approximations, and decimal approximations of \(\sin(x^3)\) evaluated at these points.
\(x_i\) Exact Approx. \(\sin(x_i^3)\)
\(x_0\) \(-\pi/4\) \(-0.7854\) \(-0.4657\)
\(x_1\) \(-7 \pi/40\) \(-0.5498\) \(-0.1654\)
\(x_2\) \(-{\pi }/{10}\) \(-0.3142\) \(-0.0310\)
\(x_3\) \(-{\pi }/{40}\) \(-0.0785\) \(-0.0005\)
\(x_4\) \({\pi }/{20}\) \(0.1571\) \(0.0039\)
\(x_5\) \({\pi }/{8}\) \(0.3927\) \(0.0605\)
\(x_6\) \({\pi }/{5}\) \(0.6283\) \(0.2455\)
\(x_7\) \({11 \pi }/{40}\) \(0.8639\) \(0.6011\)
\(x_8\) \({7 \pi }/{20}\) \(1.0996\) \(0.9710\)
\(x_{9}\) \({17 \pi }/{40}\) \(1.3352\) \(0.6899\)
\(x_{10}\) \({\pi }/{2}\) \(1.5708\) \(-0.6700\)
Figure 5.5.5. Values used to approximate \(\int_{-\frac{\pi}4}^{\frac{\pi}2}\sin(x^3)\, dx\) in Example 5.5.4
Once this table is created, it is straightforward to approximate the definite integral using the Left and Right Hand Rules. (Note: the table itself is easy to create, especially with a standard spreadsheet program on a computer. The last two columns are all that are needed.) The Left Hand Rule sums the first 10 values of \(\sin(x_i^3)\) and multiplies the sum by \(\dx\text{;}\) the Right Hand Rule sums the last 10 values of \(\sin(x_i^3)\) and multiplies by \(\dx\text{.}\) Therefore we have:
Left Hand Rule: \(\ds \int_{-\frac{\pi}4}^{\frac{\pi}2}\sin(x^3)\, dx \approx (1.9093)(0.2356) \approx 0.4498\text{.}\)
Right Hand Rule: \(\ds \int_{-\frac{\pi}4}^{\frac{\pi}2}\sin(x^3)\, dx \approx (1.705)(0.2356) \approx 0.4017\text{.}\)
Average of the Left and Right Hand Rules: 0.4258.
(a)
(b)
Figure 5.5.6. Approximating \(\int_{-\frac{\pi}4}^{\frac{\pi}2}\sin(x^3)\, dx\) in Example 5.5.4
The actual answer, accurate to 4 places after the decimal, is 0.4609. Our approximations were once again fairly good. The rectangles used in each approximation are shown in Figure 5.5.6.(a). It is clear from the graphs that using more rectangles (and hence, narrower rectangles) should result in a more accurate approximation.

Subsection 5.5.2 The Trapezoidal Rule

In Example 5.5.2 we approximated the value of \(\ds \int_0^1 e^{-x^2}\, dx\) with 5 rectangles of equal width. Figure 5.5.3 shows the rectangles used in the Left and Right Hand Rules. These graphs clearly show that rectangles do not match the shape of the graph all that well, and that accurate approximations will only come by using lots of rectangles.
Instead of using rectangles to approximate the area, we can instead use trapezoids. In Figure 5.5.7, we show the region under \(f(x) = e^{-x^2}\) on \([0,1]\) approximated with 5 trapezoids of equal width; the top “corners” of each trapezoid lies on the graph of \(f(x)\text{.}\) It is clear from this figure that these trapezoids more accurately approximate the area under \(f\) and hence should give a better approximation of \(\int_0^1 e^{-x^2}\, dx\text{.}\) (In fact, these trapezoids seem to give a great approximation of the area!)
Figure 5.5.7. Approximating \(\int_0^1 e^{-x^2}\, dx\) using 5 trapezoids of equal widths
The formula for the area of a trapezoid is given in Figure 5.5.8. We approximate \(\int_0^1 e^{-x^2}\, dx\) with these trapezoids in the following example.
Figure 5.5.8. The area of a trapezoid

Example 5.5.9. Approximating definite integrals using trapezoids.

Use 5 trapezoids of equal width to approximate \(\ds \int_0^1e^{-x^2}\, dx\text{.}\)
Solution.
To compute the areas of the 5 trapezoids in Figure 5.5.7, it will again be useful to create a table of values as shown in Figure 5.5.10.
\(x_i\) \(e^{-x_i^2}\)
\(0\) \(1\)
\(0.2\) \(0.9608\)
\(0.4\) \(0.8521\)
\(0.6\) \(0.6977\)
\(0.8\) \(0.5273\)
\(1\) \(0.3679\)
Figure 5.5.10. A table of values of \(e^{-x^2}\)
The leftmost trapezoid has legs of length \(1\) and \(0.9607\) and a height of 0.2. Thus, by our formula, the area of the leftmost trapezoid is:
\begin{equation*} \frac{1+0.9608}{2}(0.2) = 0.1961\text{.} \end{equation*}
Moving right, the next trapezoid has legs of length \(0.9607\) and \(0.8521\) and a height of 0.2. Thus its area is:
\begin{equation*} \frac{0.9608+0.8521}2(0.2) = 0.1813\text{.} \end{equation*}
The sum of the areas of all 5 trapezoids is:
\begin{align*} \frac{1+0.9608}{2}(0.2) + \frac{0.9608+0.8521}2(0.2)+\frac{0.8521+0.6977}2(0.2)\amp +\\ \frac{0.6977+0.5273}2(0.2)+\frac{0.5273+0.3679}2(0.2)\amp = 0.7444\text{.} \end{align*}
We approximate \(\int_0^1 e^{-x^2}\, dx \approx 0.7444\text{.}\)
There are many things to observe in this example. Note how each term in the final summation was multiplied by both 1/2 and by \(\dx = 0.2\text{.}\) We can factor these coefficients out, leaving a more concise summation as:
\begin{align*} \frac12(0.2)\amp\Big[(1+0.9608) + (0.9608+0.8521) + (0.8521+0.6977)\\ \amp\quad + ( 0.6977+ 0.5273) +(0.5273 + 0.3679)\Big]\text{.} \end{align*}
Now notice that all numbers except for the first and the last are added twice. Therefore we can write the summation even more concisely as
\begin{equation*} \frac{0.2}{2}\Big[1 + 2(0.9608+0.8521+0.6977+0.5273) + 0.3679\Big]\text{.} \end{equation*}
This is the heart of the Trapezoidal Rule, wherein a definite integral \(\int_a^b f(x) \, dx\) is approximated by using trapezoids of equal widths to approximate the corresponding area under \(f\text{.}\) Using \(n\) equally spaced subintervals with endpoints \(x_0\text{,}\) \(x_1\text{,}\) \(\ldots\text{,}\) \(x_{n}\text{,}\) we again have \(\ds \dx = \frac{b-a}n\text{.}\) Thus:
\begin{align*} \int_a^b f(x)\, dx \amp \approx \sum_{i=1}^n \frac{f(x_{i-1})+f(x_{i})}2\dx\\ \amp = \frac{\dx}2 \sum_{i=1}^n \big(f(x_{i-1})+f(x_{i})\big)\\ \amp = \frac{\dx}2\Big[f(x_0)+ \left(2\sum_{i=1}^{n-1} f(x_i)\right) + f(x_{n})\Big]\text{.} \end{align*}

Example 5.5.11. Using the Trapezoidal Rule.

Revisit Example 5.5.4 and approximate \(\ds\int_{-\frac{\pi}{4}}^{\frac{\pi}{2}} \sin(x^3)\, dx\) using the Trapezoidal Rule and 10 equally spaced subintervals.
Solution.
We refer back to Figure 5.5.5 for the table of values of \(\sin(x^3)\text{.}\) Recall that \(\dx = 3\pi/40 \approx 0.236\text{.}\) Thus we have:
\begin{align*} \amp \int_{-\frac{\pi}4}^{\frac{\pi}2} \sin(x^3)\, dx\\ \amp \approx \frac{0.236}{2}\Big[-0.4657 + 2\Big(-0.1654+(-0.031)+\ldots+ 0.68999\Big)+(-0.67)\Big]\\ \amp = 0.4258\text{.} \end{align*}
The actual answer, accurate to 4 decimal places is \(0.4609\text{.}\) So the Trapezoidal Rule with 10 subintervals is an under-approximation by about \(0.0351\text{.}\)
Notice how “quickly” the Trapezoidal Rule can be implemented once the table of values is created. This is true for all the methods explored in this section; the real work is creating a table of \(x_i\) and \(f(x_i)\) values. Once this is completed, approximating the definite integral is not difficult. Again, using technology is wise. Spreadsheets can make quick work of these computations and make using lots of subintervals easy.
Also notice the approximations the Trapezoidal Rule gives. It is the average of the approximations given by the Left and Right Hand Rules! This effectively renders the Left and Right Hand Rules obsolete. They are useful when first learning about definite integrals, but if a real approximation is needed, one is generally better off using the Trapezoidal Rule instead of either the Left or Right Hand Rule. However, there are two other methods that are also generally more accurate than the Left or Right Hand Rule.

Subsection 5.5.3 The Midpoint Rule

Another method that can be more accurate than the Trapezoidal Rule is the Midpoint Rule:
\begin{align*} S_M(n)\amp =\sum_{i=1}^n f\left(\frac{x_{i-1}+x_{i}}{2}\right)\Delta x\\ \amp = \sum_{i=1}^n f\left(\overline{x_i}\right)\Delta x\\ \amp \text{ where } \overline{x_i} \text{ is the midpoint of each subinterval,}\\ \amp \overline{x_i}=a+\dx\left(i-\frac12\right) \end{align*}

Example 5.5.12. Using the Midpoint Rule.

Use the Midpoint Rule with \(n=5\) to approximate \(\ds \int_0^1e^{-x^2}\, dx\text{.}\)
Solution.
We cannot use the table in Figure 5.5.10 that we used for the Trapezoidal, Right and Left Hand Rules when using the Midpoint Rule. The Trapezoidal rule averages the outputs of the function to obtain a more accurate estimate of the definite integral. The Midpoint Rule averages the inputs of each subinterval to create a rectangle with height \(f\left(\frac{x_{i-1}+x_{i}}{2}\right)\text{.}\) Generally \(f\left(\frac{x_{i-1}+x_{i}}{2}\right)\neq \frac{f(x_{i-1})+f(x_{i})}{2}\text{.}\)
So we will create a new table of values as shown in Figure 5.5.13. We have \(\dx=(1-0)/5=0.2\text{.}\) The midpoint of the first subinteval is at \(0+0.2(1/2)=0.1\) and each successive midpoint is \(0.2\) from the last.
\(x_i\) \(e^{-x_i^2}\)
\(0.1\) \(0.9900\)
\(0.3\) \(0.9139\)
\(0.5\) \(0.7788\)
\(0.7\) \(0.6126\)
\(0.9\) \(0.4449\)
Figure 5.5.13. A table of values of \(e^{-x^2}\)
So we have
\begin{align*} \int_0^1 e^{-x^2}\, dx \amp \approx 0.2(0.99+0.9139+0.7788+0.6126+0.4449)\\ \amp \approx 0.7480 \end{align*}
We approximate \(\ds \int_0^1 e^{-x^2}\, dx \approx 0.7480\text{.}\)

Example 5.5.14. Using the Midpoint Rule.

Revisit Example 5.5.11 and approximate \(\ds\int_{-\frac{\pi}{4}}^{\frac{\pi}{2}} \sin(x^3)\, dx\) using the Midpoint Rule and 10 equally spaced subintervals.
Solution.
Again, a table will be useful. Recall that \(\dx = 3\pi/40 \approx 0.2356\text{.}\) The midpoint of the first subinterval is \(\overline{x_1}=a+\dx/2=-\pi/4+3\pi/40(1/2)=-17\pi/80\) (notice that \(\overline{x_1}\) is half of a subinterval width to the right of \(a\)). Each successive midpoint is \(\dx=3 \pi/40=6\pi/80\) to the right of the last. So we have:
\(\overline{x_i}\) Exact Approx. \(\sin(x_i^3)\)
\(\overline{x_1}\) \(-17\pi/80\) \(-0.6676\) \(-0.2932\)
\(\overline{x_2}\) \(-11 \pi/80\) \(-0.4320\) \(-0.0805\)
\(\overline{x_3}\) \(-5{\pi }/{80}\) \(-0.1963\) \(-0.0076\)
\(\overline{x_4}\) \(1{\pi }/{80}\) \(-0.0393\) \(0.0001\)
\(\overline{x_5}\) \(7{\pi }/{80}\) \(0.2749\) \(0.0208\)
\(\overline{x_6}\) \({13\pi }/{80}\) \(0.5105\) \(0.1327\)
\(\overline{x_7}\) \({19\pi }/{80}\) \(0.7461\) \(0.4035\)
\(\overline{x_8}\) \({25 \pi }/{80}\) \(0.9817\) \(0.8112\)
\(\overline{x_9}\) \({31 \pi }/{80}\) \(1.2174\) \(0.9729\)
\(\overline{x_{10}}\) \({37 \pi }/{80}\) \(1.4530\) \(0.0740\)
Figure 5.5.15. Values used to approximate \(\int_{-\frac{\pi}4}^{\frac{\pi}2}\sin(x^3)\, dx\) in Example 5.5.14
Thus we have:
\begin{align*} \amp \int_{-\frac{\pi}4}^{\frac{\pi}2} \sin(x^3)\, dx\\ \amp \approx 0.2356\Big[-0.2932+(-0.0805)+(-0.0076)+\dots+0.9729+0.0740\Big]\\ \amp=0.2356\cdot 2.0339\\ \amp \approx 0.4792\text{.} \end{align*}
The actual answer, accurate to 4 decimal places is \(0.4609\text{.}\) So the Midpoint Rule with 10 subintervals is an overrapproximation by about \(0.0183 \text{.}\) Notice that this error is about half of the error in using the Trapezoidal Rule.
In many cases, the Midpoint Rule will more accurate than the Trapezoidal Rule. You may wonder though, how can we improve on the Trapezoidal and Midpoint Rules, apart from using more and more subintervals? The answer is clear once we look back and consider what we have really done so far. The Left Hand Rule, Right Hand Rule and Midpoint Rules are not really about using rectangles to approximate area. Instead, they approximate a function \(f\) with constant functions on small subintervals and then compute the definite integral of these constant functions. The Trapezoidal Rule is really approximating a function \(f\) with a linear function on a small subinterval, then computing the definite integral of this linear function. In all of these cases the definite integrals are easy to compute in geometric terms.
So we have a progression: we start by approximating \(f\) with a constant function and then with a linear function. What is next? A quadratic function. By approximating the curve of a function with lots of parabolas, we generally get an even better approximation of the definite integral. We call this process Simpson’s Rule, named after Thomas Simpson (1710-1761), even though others had used this rule as much as 100 years prior.

Subsection 5.5.4 Simpson’s Rule

Given one point, we can create a constant function that goes through that point. Given two points, we can create a linear function that goes through those points. Given three points, we can create a quadratic function that goes through those three points (given that no two have the same \(x\)-value).
Consider three points \((x_0,y_0)\text{,}\) \((x_1,y_1)\) and \((x_2,y_2)\) whose \(x\)-values are equally spaced and \(x_0\lt x_1\lt x_2\text{.}\) Let \(f\) be the quadratic function that goes through these three points. It is not hard to show that
\begin{equation} \int_{x_0}^{x_2} f(x)\, dx = \frac{x_2-x_0}{6}\big(y_0+4y_1+y_2\big)\text{.}\tag{5.5.1} \end{equation}
Consider Figure 5.5.16. A function \(f\) goes through the 3 points shown and the parabola \(g\) that also goes through those points is graphed with a dashed line. Using our equation from above, we know exactly that
\begin{equation*} \int_1^3 g(x) \, dx = \frac{3-1}{6}\big(3+4(1)+2\big)= 3\text{.} \end{equation*}
Since \(g\) is a good approximation for \(f\) on \([1,3]\text{,}\) we can state that
\begin{equation*} \int_1^3 f(x)\, dx \approx 3\text{.} \end{equation*}
Figure 5.5.16. A graph of a function \(f\) and a parabola that approximates it well on \([1,3]\)
Notice how the interval \([1,3]\) was split into two subintervals as we needed 3 points. Because of this, whenever we use Simpson’s Rule, we need to break the interval into an even number of subintervals.
In general, to approximate \(\ds \int_a^b f(x)\, dx\) using Simpson’s Rule, subdivide \([a,b]\) into \(n\) subintervals, where \(n\) is even and each subinterval has width \(\dx = (b-a)/n\text{.}\) We approximate \(f\) with \(n/2\) parabolic curves, using Equation (5.5.1) to compute the area under these parabolas. Adding up these areas gives the formula:
\begin{equation*} \int_a^b f(x) \, dx \approx \frac{\dx}3\Big[f(x_0)+4f(x_1)+2f(x_2)+4f(x_3)+\ldots+2f(x_{n-2})+4f(x_{n-1})+f(x_{n})\Big]\text{.} \end{equation*}
Note how the coefficients of the terms in the summation have the pattern 1, 4, 2, 4, 2, 4, \(\ldots\text{,}\) 2, 4, 1.
Figure 5.5.17 illustrates how the area calculated by Simpson’s Rule approximates \(\int_0^5 f(x)\, dx\) for the function \(f(x)=\sin(\pi x)\text{.}\) In this case, \(8\) subintervals were used, resulting in \(4\) quadratic curves (dashed lines) being fitted to each pair of subintervals. The actual answer (accurate to \(4\) decimal places) is about \(10.6366\text{,}\) while Simpson’s rule gives \(10.7294\text{.}\) Of course more subintervals would result in better accuracy. However \(8\) intervals were chosen specifically so that you could see how the parabolas compare to the original function. With larger values of \(n\text{,}\) it becomes difficult to distinguish the function and its quadratic approximations on each subinterval.
Figure 5.5.17. An illustration of Simpson’s rule on \(f(x)=\sin(\pi x)+2\) over \([0,5]\) using \(8\) subintervals, resulting in \(4\) quadratic approximations
Let’s demonstrate Simpson’s Rule with a concrete example.

Example 5.5.18. Using Simpson’s Rule.

Approximate \(\ds\int_0^1 e^{-x^2}\, dx\) using Simpson’s Rule and 4 equally spaced subintervals.
Solution.
We begin by making a table of values as we have in the past, as shown in Figure 5.5.19.(a).
\(x_i\) \(e^{-x_i^2}\)
\(0\) \(1\)
\(0.25\) \(0.939\)
\(0.5\) \(0.779\)
\(0.75\) \(0.570\)
\(1\) \(0.368\)
(a)
(b)
Figure 5.5.19. A table of values to approximate \(\int_0^1e^{-x^2}\, dx\text{,}\) along with a graph of the function
Simpson’s Rule states that
\begin{equation*} \int_0^1e^{-x^2}\, dx \approx \frac{0.25}{3}\Big[1+4(0.939)+2(0.779)+4(0.570) + 0.368\Big] = 0.7468\overline{3}\text{.} \end{equation*}
Recall in Example 5.5.2 we stated that the correct answer, accurate to 4 places after the decimal, was 0.7468. Our approximation with Simpson’s Rule, with 4 subintervals, is better than our approximation with the Trapezoidal Rule using 5!
Figure 5.5.19.(b) shows \(f(x) = e^{-x^2}\) along with its approximating parabolas, demonstrating how good our approximation is. The approximating curves are nearly indistinguishable from the actual function.

Example 5.5.20. Using Simpson’s Rule.

Approximate \(\ds\int_{-\frac{\pi}4}^{\frac{\pi}2} \sin(x^3)\, dx\) using Simpson’s Rule and 10 equally spaced intervals.
Solution.
Figure 5.5.21 shows the table of values that we used in the past for this problem, shown here again for convenience. Again, \(\dx = (\pi/2+\pi/4)/10 \approx 0.236\text{.}\)
\(x_i\) \(\sin(x_i^3)\)
\(-0.7854\) \(-0.4657\)
\(-0.5498\) \(-0.1654\)
\(-0.3142\) \(-0.0310\)
\(-0.0785\) \(-0.0005\)
\(0.1571\) \(0.0039\)
\(0.3927\) \(0.0605\)
\(0.6283\) \(0.2455\)
\(0.8639\) \(0.6011\)
\(1.0996\) \(0.9710\)
\(1.3352\) \(0.6899\)
\(1.5708\) \(-0.6700\)
Figure 5.5.21. Values used to approximate \(\int_{-\frac{\pi}4}^{\frac{\pi}2}\sin(x^3)\, dx\) in Example 5.5.20
Simpson’s Rule states that
\begin{align*} \int_{-\frac{\pi}4}^{\frac{\pi}2} \sin(x^3)\, dx \amp \approx \frac{0.2356}3\Big[(-0.4657)+4(-0.1654)+2(-0.0310) + \ldots\\ \amp \ldots + 2(0.9710) + 4(0.6899) + (-0.6700)\big]\\ \amp \approx 0.4701 \end{align*}
Figure 5.5.22. Approximating \(\int_{-\frac{\pi}4}^{\frac{\pi}2}\sin(x^3)\, dx\) in Example 5.5.20 with Simpson’s Rule and 10 equally spaced intervals
Recall that the actual value, accurate to 3 decimal places, is 0.4609. Our approximation is within one \(1/100\)th of the correct value. The graph in Figure 5.5.22 shows how closely the parabolas match the shape of the graph.

Subsection 5.5.5 Summary and Error Analysis

We summarize the key concepts of this section thus far in the following Key Idea.

Key Idea 5.5.23. Numerical Integration.

Let \(f\) be a continuous function on \([a,b]\text{,}\) let \(n\) be a positive integer, and let \(\ds\dx = \frac{b-a}{n}\text{.}\)
Set \(x_0=a\text{,}\) \(x_1 = a+\dx\text{,}\) \(\ldots\text{,}\) \(x_i = a+i\dx\text{,}\) \(x_{n}=b\text{.}\)
Consider \(\ds\int_a^b f(x)\, dx\text{.}\)
Left Hand Rule: \(\ds\int_a^b f(x)\, dx \approx \dx\big[f(x_0) + f(x_1) + \ldots + f(x_{n-1})\big]\text{.}\)
Right Hand Rule: \(\ds\int_a^b f(x)\, dx \approx \dx\big[f(x_1) + f(x_2) + \ldots + f(x_{n})\big]\text{.}\)
Trapezoidal Rule: \(\ds\int_a^b f(x)\, dx \approx \frac{\dx}2\big[f(x_0) + 2f(x_1) + 2f(x_2) +\ldots + 2f(x_{n-1})+ f(x_{n})\big]\text{.}\)
Midpoint Rule: \(\ds \int_a^b f(x)\, dx \approx \sum_{i=1}^n f\left(\frac{x_{i-1}+x_{i}}{2}\right)\Delta x\text{.}\)
Simpson’s Rule: \(\ds\int_a^b f(x)\, dx \approx \frac{\dx}3\big[f(x_0) + 4f(x_1) + 2f(x_2) +\ldots + 4f(x_{n-1})+ f(x_{n})\big] \text{ for } n \text{ even}\text{.}\)
In our examples, we approximated the value of a definite integral using a given method then compared it to the “right” answer. This should have raised several questions in the reader’s mind, such as:
  1. How was the “right” answer computed?
  2. If the right answer can be found, what is the point of approximating?
  3. If there is value to approximating, how are we supposed to know if the approximation is any good?
These are good questions, and their answers are educational. In the examples, the right answer was never computed. Rather, an approximation accurate to a certain number of places after the decimal was given. In Example 5.5.2, we do not know the exact answer, but we know it starts with \(0.7468\text{.}\) These more accurate approximations were computed using numerical integration but with more precision (i.e., more subintervals and the help of a computer).
Since the exact answer cannot be found, approximation still has its place. How are we to tell if the approximation is any good?
“Trial and error” provides one way. Using technology, make an approximation with, say, 10, 100, and 200 subintervals. This likely will not take much time at all, and a trend should emerge. If a trend does not emerge, try using yet more subintervals. Keep in mind that trial and error is never foolproof; you might stumble upon a problem in which a trend will not emerge.
A second method is to use Error Analysis. While the details are beyond the scope of this text, there are some formulas that give bounds for how good your approximation will be. For instance, the formula might state that the approximation is within 0.1 of the correct answer. If the approximation is 1.58, then one knows that the correct answer is between 1.48 and 1.68. By using lots of subintervals, one can get an approximation as accurate as one likes. Theorem 5.5.24 states what these bounds are.
There are some key things to note about this theorem.
  1. The larger the interval, the larger the error. This should make sense intuitively.
  2. The error shrinks as more subintervals are used (i.e., as \(n\) gets larger).
  3. The maximum error in the Midpoint Rule is half of the maximum error in the Trapezoidal Rule. (Usually the errors in these two rules have opposite signs as well, that is one will be an under approximation and the other will be an over approximation).
  4. The error in Simpson’s Rule has a term relating to the \(4\)th derivative of \(f\text{.}\) Consider a cubic polynomial: its \(4\)th derivative is 0. Therefore, the error in approximating the definite integral of a cubic polynomial with Simpson’s Rule is \(0\) — Simpson’s Rule computes the exact answer!
We revisit Examples 5.5.9 and Example 5.5.18 and compute the error bounds using Theorem 5.5.24 in the following example.

Example 5.5.25. Computing error bounds.

Find the error bounds when approximating \(\ds \int_0^1 e^{-x^2}\, dx\) using the Trapezoidal and Midpoint Rules and 5 subintervals, and using Simpson’s Rule with 4 subintervals.
Solution.
Trapezoidal and Midpoints Rules with \(n=5\text{:}\)
We start by computing the \(2\)nd derivative of \(f(x) = e^{-x^2}\text{:}\)
\begin{equation*} \fpp(x) = e^{-x^2}(4x^2-2)\text{.} \end{equation*}
Figure 5.5.26 shows a graph of \(\fpp(x)\) on \([0,1]\text{.}\) It is clear that the largest value of \(\fpp\text{,}\) in absolute value, is 2.
Figure 5.5.26. Graphing \(\fpp(x)\) in Example 5.5.25 to help establish error bounds
Thus we let \(K=2\) and apply the error formula from Theorem 5.5.24.
\begin{equation*} E_T \leq \frac{(1-0)^3}{12\cdot 5^2}\cdot 2 = 0.00\overline{6}\text{.} \end{equation*}
Since the maximum error in the Midpoint rule is half the error in the Trapezoidal Rule, we can say: \(E_M \leq 0.00\overline{3}\)
Our error estimation formula states that our approximation of 0.7444 found in Example 5.5.9 is within 0.0067 of the correct answer. Hence we know that the actual value is within \([0.7444-0.0067, 0.7444+0.0067]=[0.7377,0.7511].\) So:
\begin{equation*} 0.7377 \leq \int_0^1e^{-x^2}\, dx \leq 0.7511 \end{equation*}
But we can do better than this with the Midpoint Rule since its error is at most half of the error of the Trapezoidal Rule. Our error estimate formula state that our approximate of \(0.7480\) found in Example 5.5.12 is within \(0.0034\) of the correct answer. Hence Hence we know that the actual value is within \([0.7480-0.0034, 0.7480+0.0033]=[0.7447,0.7513]\text{.}\)
We had earlier stated the actual answer, correct to 4 decimal places, to be 0.7468, affirming the validity of Theorem 5.5.24.
Simpson’s Rule with \(n=4\text{:}\)
We start by computing the \(4\)th derivative of \(f(x) = e^{-x^2}\text{:}\)
\begin{equation*} f^{(4)}(x) = e^{-x^2}(16x^4-48x^2+12)\text{.} \end{equation*}
Figure 5.5.27 shows a graph of \(f^{(4)}(x)\) on \([0,1]\text{.}\) It is clear that the largest value of \(f^{(4)}\text{,}\) in absolute value, is 12. Thus we let \(K=12\) and apply the error formula from Theorem 5.5.24.
\begin{equation*} E_s =\leq \frac{(1-0)^5}{180\cdot 4^4}\cdot 12 = 0.00026\text{.} \end{equation*}
Figure 5.5.27. Graphing \(f^{(4)}(x)\) in Example 5.5.25 to help establish error bounds
Our error estimation formula states that our approximation of \(0.7468\overline{3}\) found in Example 5.5.18 is within \(0.00026\) of the correct answer, hence we know that the correct answer is in the interval \([0.74683-0.00026 , 0.74683 + 0.00026]=[0.74657,0.74709].\) So:
\begin{equation*} 0.74657 \leq \int_0^1e^{-x^2}\, dx \leq 0.74709\text{.} \end{equation*}
Once again we affirm the validity of Theorem 5.5.24 since the answer to 4 decimal places is actually \(0.7468\text{.}\)
At the beginning of this section we mentioned two main situations where numerical integration was desirable. We have considered the case where an antiderivative of the integrand cannot be computed. We now investigate the situation where the integrand is not known. This is, in fact, the most widely used application of Numerical Integration methods. “Most of the time” we observe behavior but do not know “the” function that describes it. We instead collect data about the behavior and make approximations based on this data. We demonstrate this in an example.

Example 5.5.28. Approximating distance traveled.

One of the authors drove his daughter home from school while she recorded their speed every 30 seconds. The data is given in Figure 5.5.29. Approximate the distance they traveled.
Time Speed
(min) (mph)
\(0\) \(0\)
\(1\) \(25\)
\(2\) \(22\)
\(3\) \(19\)
\(4\) \(39\)
\(5\) \(0\)
\(6\) \(43\)
\(7\) \(59\)
\(8\) \(54\)
\(9\) \(51\)
\(10\) \(43\)
\(11\) \(35\)
\(12\) \(40\)
\(13\) \(43\)
\(14\) \(30\)
\(15\) \(0\)
\(16\) \(0\)
\(17\) \(28\)
\(18\) \(40\)
\(19\) \(42\)
\(20\) \(40\)
\(21\) \(39\)
\(22\) \(40\)
\(23\) \(23\)
\(24\) \(0\)
Figure 5.5.29. Speed data collected at 30 second intervals for Example 5.5.28
Solution.
Recall that by integrating a speed function we get distance traveled. We have information about \(v(t)\text{;}\) we will use Simpson’s Rule to approximate \(\ds \int_a^b v(t)\, dt\text{.}\)
The most difficult aspect of this problem is converting the given data into the form we need it to be in. The speed is measured in miles per hour, whereas the time is measured in minutes.
We need to compute \(\dx = (b-a)/n\text{.}\) With 25 data points collected, there are \(n=24\) subintervals. What are \(a\) and \(b\text{?}\) Since we start at time \(t=0\text{,}\) we have \(a=0\text{.}\) The final recorded time was \(t=12\) minutes, which is 1/5 of an hour. Thus we have
\begin{equation*} \dx = \frac{b-a}{n} = \frac{1/5-0}{24} = \frac1{120}; \frac{\dx}{3} = \frac{1}{360}\text{.} \end{equation*}
Thus the distance traveled is approximately:
\begin{align*} \int_0^{0.2}v(t)\, dt \amp \approx \frac{1}{360}\Big[f(x_0)+4f(x_1) + 2f(x_2) + \cdots + 4f(x_{n-1})+f(x_{n})\Big]\\ \amp = \frac{1}{360}\Big[0+4\cdot25+2\cdot 22 + \cdots + 2\cdot40+4\cdot 23 + 0\Big]\\ \amp \approx 6.2167 \,\text{ miles. } \end{align*}
We approximate the author drove 6.2 miles. (Because we are sure the reader wants to know, the author’s odometer recorded the distance as about 6.05 miles.)

Exercises 5.5.6 Exercises

Terms and Concepts

1.
T/F: Simpson’s Rule is a method of approximating antiderivatives.
  • True
  • False
2.
What are the two basic situations where approximating the value of a definite integral is necessary?
3.
Why are the Left and Right Hand Rules rarely used?
4.
Simpson’s Rule is based on approximating portions of a function with what type of function?

Problems

Exercise Group.
In the following exercises, approximate the definite integral with the Trapezoidal Rule and Simpson’s Rule, with \(n=4\text{.}\) Then find the exact value.
5.
For the integral \(\int_{-1}^1 x^2\, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
(c)
Find the exact value:
6.
For the integral \(\int_{0}^{10} 5x\, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
(c)
Find the exact value:
7.
For the integral \(\int_{0}^{\pi} \sin(x) \, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
(c)
Find the exact value:
8.
For the integral \(\int_{0}^{4} \sqrt x\, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
(c)
Find the exact value:
9.
For the integral \(\int_{0}^{3} (x^3+2x^2-5x+7)\, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
(c)
Find the exact value:
10.
For the integral \(\int_{0}^{1} x^4\, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
(c)
Find the exact value:
11.
For the integral \(\int_{0}^{2\pi} \cos(x) \, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
(c)
Find the exact value:
12.
For the integral \(\int_{-3}^{3} \sqrt{9-x^2} \, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
(c)
Find the exact value:
Exercise Group.
In the following exercises, approximate the definite integral with the Trapezoidal Rule and Simpson’s Rule, with \(n=6\text{.}\)
13.
For the integral \(\int_{0}^{1} \cos\big(x^2\big) \, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
14.
For the integral \(\int_{-1}^{1} e^{x^2} \, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
15.
For the integral \(\int_{0}^{5} \sqrt{x^2+1} \, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
16.
For the integral \(\int_{0}^{\pi} x\sin(x) \, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
17.
For the integral \(\int_{0}^{\pi/2} \sqrt{\cos(x) } \, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
18.
For the integral \(\int_{1}^{4} \ln(x) \, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
19.
For the integral \(\int_{-1}^{1} \frac{1}{\sin(x) +2} \, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
20.
For the integral \(\int_{0}^{6} \frac{1}{\sin(x) +2} \, dx\text{:}\)
(a)
Approximate using the trapezoidal rule:
(b)
Approximate using Simpson’s rule:
Exercise Group.
In the following exercises, find \(n\) such that the error in approximating the given definite integral is less than \(0.0001\) when using the Trapezoidal Rule and Simpson’s Rule.
21.
For the integral \(\int_{0}^{\pi} \sin(x) \, dx\text{:}\)
(a)
Trapezoid rule: \(n \gt =\)
(b)
Simpson’s rule: \(n \gt =\)
22.
For the integral \(\int_{1}^{4} \frac{1}{\sqrt x} \, dx\text{:}\)
(a)
Trapezoid rule: \(n \gt =\)
(b)
Simpson’s rule: \(n \gt =\)
23.
For the integral \(\int_{0}^{\pi} \cos\big(x^2\big) \, dx\text{:}\)
(a)
Trapezoid rule: \(n \gt =\)
(b)
Simpson’s rule: \(n \gt =\)
24.
For the integral \(\int_{0}^{5} x^4 \, dx\text{:}\)
(a)
Trapezoid rule: \(n \gt =\)
(b)
Simpson’s rule: \(n \gt =\)
Exercise Group.
In the following exercises, a region is given. Find the area of the region using Simpson’s Rule:
  1. where the measurements are in centimeters, taken in 1 cm increments, and
  2. where the measurements are in hundreds of feet, taken in 100 ft increments.
25.
26.
You have attempted of activities on this page.