Skip to main content
Logo image

Active Calculus

Section 5.6 Numerical Integration

When we first explored finding the net signed area bounded by a curve, we developed the concept of a Riemann sum as a helpful estimation tool and a key step in the definition of the definite integral. Recall that the left, right, and middle Riemann sums of a function f on an interval [a,b] are given by
(5.6.1)Ln=f(x0)Δx+f(x1)Δx++f(xn1)Δx=i=0n1f(xi)Δx,(5.6.2)Rn=f(x1)Δx+f(x2)Δx++f(xn)Δx=i=1nf(xi)Δx,(5.6.3)Mn=f(x1)Δx+f(x2)Δx++f(xn)Δx=i=1nf(xi)Δx,
where x0=a, xi=a+iΔx, xn=b, and Δx=ban. For the middle sum, we defined xi=(xi1+xi)/2.
A Riemann sum is a sum of (possibly signed) areas of rectangles. The value of n determines the number of rectangles, and our choice of left endpoints, right endpoints, or midpoints determines the heights of the rectangles. We can see the similarities and differences among these three options in Figure 5.6.1, where we consider the function f(x)=120(x4)3+7 on the interval [1,8], and use 5 rectangles for each of the Riemann sums.
Figure 5.6.1. Left, right, and middle Riemann sums for y=f(x) on [1,8] with 5 subintervals.
While it is a good exercise to compute a few Riemann sums by hand, just to ensure that we understand how they work and how varying the function, the number of subintervals, and the choice of endpoints or midpoints affects the result, using computing technology is the best way to determine Ln, Rn, and Mn. Any computer algebra system will offer this capability; as we saw in Preview Activity 4.3.1, a straightforward option that is freely available online is this applet
 1 
gvsu.edu/s/a9
. Note that we can adjust the formula for f(x), the window of x- and y-values of interest, the number of subintervals, and the method. (See Preview Activity 4.3.1 for any needed reminders on how the applet works.)
In this section we explore several different alternatives for estimating definite integrals. Our main goal is to develop formulas to estimate definite integrals accurately without using a large numbers of rectangles.

Preview Activity 5.6.1.

As we begin to investigate ways to approximate definite integrals, it will be insightful to compare results to integrals whose exact values we know. To that end, the following sequence of questions centers on 03x2dx.
(a) Use the Desmos graph at https://www.desmos.com/calculator/jnhujcwbie
 2 
www.desmos.com/calculator/jnhujcwbie
(The link opens a new tab/window) with the function f(x)=x2 on the window of x values from 0 to 3 to compute L3, the left Riemann sum with three subintervals.
L3=
(b) Likewise, use the same Desmos graph to compute R3 and M3, the right and middle Riemann sums with three subintervals, respectively.
R3=
M3=
(c) Use the Fundamental Theorem of Calculus to compute the exact value of I=03x2dx.
I=
(d) We define the error in an approximation of a definite integral to be the difference between the integral’s exact value (I and the approximation’s value. What is the error that results from using L3? From R3? From M3?
IL3=
IR3=
IM3=
(e) In what follows in this section, we will learn a new approach to estimating the value of a definite integral known as the Trapezoid Rule. The basic idea is to use trapezoids, rather than rectangles, to estimate the area under a curve. What is the formula for the area of a trapezoid with bases of length b1 and b2 and height h? (Type b1 and b2 for the bases).
(f) Working by hand, estimate the area under f(x)=x2 on [0,3] using three subintervals and three corresponding trapezoids.
T3=
What is the error in this approximation? IT3=
How does it compare to the errors you calculated in (d)? Select all answers that are true.
  1. Smaller in magnitude than L3 error and R3 error, but more than M3 error
  2. More in magnitude than L3 error
  3. Opposite sign compared with M3 error
  4. Less in magnitude than M3 error
  5. 2 times the magnitude as compared with M3 error
  6. More in magnitude than R3 error
  7. None of the above.

Subsection 5.6.1 The Trapezoid Rule

So far, we have used the simplest possible quadrilaterals (that is, rectangles) to estimate areas. It is natural, however, to wonder if other familiar shapes might serve us even better.
An alternative to Ln, Rn, and Mn is called the Trapezoid Rule. Rather than using a rectangle to estimate the (signed) area bounded by y=f(x) on a small interval, we use a trapezoid. For example, in Figure 5.6.2, we estimate the area under the curve using three subintervals and the trapezoids that result from connecting the corresponding points on the curve with straight lines.
Figure 5.6.2. Estimating abf(x) dx using three subintervals and trapezoids, rather than rectangles, where a=x0 and b=x3.
The biggest difference between the Trapezoid Rule and a Riemann sum is that on each subinterval, the Trapezoid Rule uses two function values, rather than one, to estimate the (signed) area bounded by the curve. For instance, to compute D1, the area of the trapezoid on [x0,x1], we observe that the left base has length f(x0), while the right base has length f(x1). The height of the trapezoid is x1x0=Δx=ba3. The area of a trapezoid is the average of the bases times the height, so we have
D1=12(f(x0)+f(x1))Δx.
Using similar computations for D2 and D3, we find that T3, the trapezoidal approximation to abf(x)dx is given by
T3=D1+D2+D3=12(f(x0)+f(x1))Δx+12(f(x1)+f(x2))Δx+12(f(x2)+f(x3))Δx.
Because both left and right endpoints are being used, we recognize within the trapezoidal approximation the use of both left and right Riemann sums. Rearranging the expression for T3 by removing factors of 12 and Δx, grouping the left endpoint and right endpoint evaluations of f, we see that
(5.6.4)T3=12[f(x0)+f(x1)+f(x2)]Δx+12[f(x1)+f(x2)+f(x3)]Δx.
We now observe that two familiar sums have arisen. The left Riemann sum L3 is L3=f(x0)Δx+f(x1)Δx+f(x2)Δx, and the right Riemann sum is R3=f(x1)Δx+f(x2)Δx+f(x3)Δx. Substituting L3 and R3 for the corresponding expressions in Equation (5.6.4), it follows that T3=12[L3+R3]. We have thus seen a very important result: using trapezoids to estimate the (signed) area bounded by a curve is the same as averaging the estimates generated by using left and right endpoints.

The Trapezoid Rule.

The trapezoidal approximation, Tn, of the definite integral abf(x)dx using n subintervals is given by the rule
Tn=([12(f(x0)+f(x1))+12(f(x1)+f(x2))++12(f(xn1)+f(xn))]Δx.=(i=0n112(f(xi)+f(xi+1))Δx.
Moreover, Tn=12[Ln+Rn].

Activity 5.6.2.

In this activity, we explore the relationships among the errors generated by left, right, midpoint, and trapezoid approximations to the definite integral 121x2dx.
  1. Use the First FTC to evaluate 121x2dx exactly.
  2. Use appropriate computing technology to compute the following approximations for 121x2dx: T4, M4, T8, and M8.
  3. Let the error that results from an approximation be the approximation’s value minus the exact value of the definite integral. For instance, if we let ET,4 represent the error that results from using the trapezoid rule with 4 subintervals to estimate the integral, we have
    ET,4=T4121x2dx.
    Similarly, we compute the error of the midpoint rule approximation with 8 subintervals by the formula
    EM,8=M8121x2dx.
    Based on your work in (a) and (b) above, compute ET,4, ET,8, EM,4, EM,8.
  4. Which rule consistently over-estimates the exact value of the definite integral? Which rule consistently under-estimates the definite integral?
  5. What behavior(s) of the function f(x)=1x2 lead to your observations in (d)?

Subsection 5.6.2 Comparing the Midpoint and Trapezoid Rules

We know from the definition of the definite integral that if we let n be large enough, we can make any of the approximations Ln, Rn, and Mn as close as we’d like (in theory) to the exact value of abf(x)dx. Thus, it may be natural to wonder why we ever use any rule other than Ln or Rn (with a sufficiently large n value) to estimate a definite integral. One of the primary reasons is that as n, Δx=ban0, and thus in a Riemann sum calculation with a large n value, we end up multiplying by a number that is very close to zero. Doing so often generates roundoff error, because representing numbers close to zero accurately is a persistent challenge for computers.
Hence, we explore ways to estimate definite integrals to high levels of precision, but without using extremely large values of n. Paying close attention to patterns in errors, such as those observed in Activity 5.6.2, is one way to begin to see some alternate approaches.
To begin, we compare the errors in the Midpoint and Trapezoid rules. First, consider a function that is concave up on a given interval, and picture approximating the area bounded on that interval by both the Midpoint and Trapezoid rules using a single subinterval.
Figure 5.6.3. Estimating abf(x) dx using a single subinterval: at left, the trapezoid rule; in the middle, the midpoint rule; at right, a modified way to think about the midpoint rule.
As seen in Figure 5.6.3, it is evident that whenever the function is concave up on an interval, the Trapezoid Rule with one subinterval, T1, will overestimate the exact value of the definite integral on that interval. From a careful analysis of the line that bounds the top of the rectangle for the Midpoint Rule (shown in magenta), we see that if we rotate this line segment until it is tangent to the curve at the midpoint of the interval (as shown at right in Figure 5.6.3), the resulting trapezoid has the same area as M1, and this value is less than the exact value of the definite integral. Thus, when the function is concave up on the interval, M1 underestimates the integral’s true value.
Figure 5.6.4. Comparing the error in estimating abf(x) dx using a single subinterval: in red, the error from the Trapezoid rule; in light red, the error from the Midpoint rule.
These observations extend easily to the situation where the function’s concavity remains consistent but we use larger values of n in the Midpoint and Trapezoid Rules. Hence, whenever f is concave up on [a,b], Tn will overestimate the value of abf(x)dx, while Mn will underestimate abf(x)dx. The reverse observations are true in the situation where f is concave down.
Next, we compare the size of the errors between Mn and Tn. Again, we focus on M1 and T1 on an interval where the concavity of f is consistent. In Figure 5.6.4, where the error of the Trapezoid Rule is shaded in red, while the error of the Midpoint Rule is shaded lighter red, it is visually apparent that the error in the Trapezoid Rule is more significant. To see how much more significant, let’s consider two examples and some particular computations.
If we let f(x)=1x2 and consider 01f(x)dx, we know by the First FTC that the exact value of the integral is
01(1x2)dx=xx33|01=23.
Using appropriate technology to compute M4, M8, T4, and T8, as well as the corresponding errors EM,4, EM,8, ET,4, and ET,8, as we did in Activity 5.6.2, we find the results summarized in Table 5.6.5. We also include the approximations and their errors for the example 121x2dx from Activity 5.6.2.
Table 5.6.5. Calculations of T4, M4, T8, and M8, along with corresponding errors, for the definite integrals 01(1x2) dx and 121x2 dx.
Rule 01(1x2)dx=0.6 error 121x2dx=0.5 error
T4 0.65625 0.0104166667 0.5089937642 0.0089937642
M4 0.671875 0.0052083333 0.4955479365 0.0044520635
T8 0.6640625 0.0026041667 0.5022708502 0.0022708502
M8 0.66796875 0.0013020833 0.4988674899 0.0011325101
For a given function f and interval [a,b], ET,4=T4abf(x)dx calculates the difference between the approximation generated by the Trapezoid Rule with n=4 and the exact value of the definite integral. If we look at not only ET,4, but also the other errors generated by using Tn and Mn with n=4 and n=8 in the two examples noted in Table 5.6.5, we see an evident pattern. Not only is the sign of the error (which measures whether the rule generates an over- or under-estimate) tied to the rule used and the function’s concavity, but the magnitude of the errors generated by Tn and Mn seems closely connected. In particular, the errors generated by the Midpoint Rule seem to be about half the size (in absolute value) of those generated by the Trapezoid Rule.
That is, we can observe in both examples that EM,412ET,4 and EM,812ET,8. This property of the Midpoint and Trapezoid Rules turns out to hold in general: for a function of consistent concavity, the error in the Midpoint Rule has the opposite sign and approximately half the magnitude of the error of the Trapezoid Rule. Written symbolically,
EM,n12ET,n.
This important relationship suggests a way to combine the Midpoint and Trapezoid Rules to create an even more accurate approximation to a definite integral.

Subsection 5.6.3 Simpson’s Rule

When we first developed the Trapezoid Rule, we observed that it is an average of the Left and Right Riemann sums:
Tn=12(Ln+Rn).
If a function is always increasing or always decreasing on the interval [a,b], one of Ln and Rn will over-estimate the true value of abf(x)dx, while the other will under-estimate the integral. Thus, the errors that result from Ln and Rn will have opposite signs; so averaging Ln and Rn eliminates a considerable amount of the error present in the respective approximations. In a similar way, it makes sense to think about averaging Mn and Tn in order to generate a still more accurate approximation.
We’ve just observed that Mn is typically about twice as accurate as Tn. So we use the weighted average
(5.6.5)S2n=2Mn+Tn3.
The rule for S2n giving by Equation (5.6.5) is usually known as Simpson’s Rule.
 3 
Thomas Simpson was an 18th century mathematician; his idea was to extend the Trapezoid rule, but rather than using straight lines to build trapezoids, to use quadratic functions to build regions whose area was bounded by parabolas (whose areas he could find exactly). Simpson’s Rule is often developed from the more sophisticated perspective of using interpolation by quadratic functions.
Note that we use “S2n” rather that “Sn” since the n points the Midpoint Rule uses are different from the n points the Trapezoid Rule uses, and thus Simpson’s Rule is using 2n points at which to evaluate the function. We build upon the results in Table 5.6.5 to see the approximations generated by Simpson’s Rule. In particular, in Table 5.6.6, we include all of the results in Table 5.6.5, but include additional results for S8=2M4+T43 and S16=2M8+T83.
Table 5.6.6. Table 5.6.5 updated to include S8, S16, and the corresponding errors.
Rule 01(1x2)dx=0.6 error 121x2dx=0.5 error
T4 0.65625 0.0104166667 0.5089937642 0.0089937642
M4 0.671875 0.0052083333 0.4955479365 0.0044520635
S8 0.6666666667 0 0.5000298792 0.0000298792
T8 0.6640625 0.0026041667 0.5022708502 0.0022708502
M8 0.66796875 0.0013020833 0.4988674899 0.0011325101
S16 0.6666666667 0 0.5000019434 0.0000019434
The results seen in Table 5.6.6 are striking. If we consider the S16 approximation of 121x2dx, the error is only ES,16=0.0000019434. By contrast, L8=0.5491458502, so the error of that estimate is EL,8=0.0491458502. Moreover, we observe that generating the approximations for Simpson’s Rule is almost no additional work: once we have Ln, Rn, and Mn for a given value of n, it is a simple exercise to generate Tn, and from there to calculate S2n. Finally, note that the error in the Simpson’s Rule approximations of 01(1x2)dx is zero!
 4 
Similar to how the Midpoint and Trapezoid approximations are exact for linear functions, Simpson’s Rule approximations are exact for quadratic and cubic functions. See additional discussion on this issue later in the section and in the exercises.
These rules are not only useful for approximating definite integrals such as 01ex2dx, for which we cannot find an elementary antiderivative of ex2, but also for approximating definite integrals when we are given a function through a table of data.

Activity 5.6.3.

A car traveling along a straight road is braking and its velocity is measured at several different points in time, as given in the following table. Assume that v is continuous, always decreasing, and always decreasing at a decreasing rate, as is suggested by the data.
seconds, t Velocity in ft/sec, v(t)
0 100
0.3 99
0.6 96
0.9 90
1.2 80
1.5 50
1.8 0
Table 5.6.7. Data for the braking car.
Figure 5.6.8. Axes for plotting the data in Activity 5.6.3.
  1. Plot the given data on the set of axes provided in Figure 5.6.8 with time on the horizontal axis and the velocity on the vertical axis.
  2. What definite integral will give you the exact distance the car traveled on [0,1.8]?
  3. Estimate the total distance traveled on [0,1.8] by computing L3, R3, and T3. Which of these under-estimates the true distance traveled?
  4. Estimate the total distance traveled on [0,1.8] by computing M3. Is this an over- or under-estimate? Why?
  5. Using your results from (c) and (d), improve your estimate further by using Simpson’s Rule.
  6. What is your best estimate of the average velocity of the car on [0,1.8]? Why? What are the units on this quantity?

Subsection 5.6.4 Overall observations regarding Ln, Rn, Tn, Mn, and S2n.

As we conclude our discussion of numerical approximation of definite integrals, it is important to summarize general trends in how the various rules over- or under-estimate the true value of a definite integral, and by how much. To revisit some past observations and see some new ones, we consider the following activity.

Activity 5.6.4.

Consider the functions f(x)=2x2, g(x)=2x3, and h(x)=2x4, all on the interval [0,1]. For each of the questions that require a numerical answer in what follows, write your answer exactly in fraction form.
  1. On the three sets of axes provided in Figure 5.6.9, sketch a graph of each function on the interval [0,1], and compute L1 and R1 for each. What do you observe?
  2. Compute M1 for each function to approximate 01f(x)dx, 01g(x)dx, and 01h(x)dx, respectively.
  3. Compute T1 for each of the three functions, and hence compute S2 for each of the three functions.
  4. Evaluate each of the integrals 01f(x)dx, 01g(x)dx, and 01h(x)dx exactly using the First FTC.
  5. For each of the three functions f, g, and h, compare the results of L1, R1, M1, T1, and S2 to the true value of the corresponding definite integral. What patterns do you observe?
Figure 5.6.9. Axes for plotting the functions in Activity 5.6.4.
The results seen in Activity 5.6.4 generalize nicely. For instance, if f is decreasing on [a,b], Ln will over-estimate the exact value of abf(x)dx, and if f is concave down on [a,b], Mn will over-estimate the exact value of the integral. An excellent exercise is to write a collection of scenarios of possible function behavior, and then categorize whether each of Ln, Rn, Tn, and Mn is an over- or under-estimate.
Finally, we make two important notes about Simpson’s Rule. When T. Simpson first developed this rule, his idea was to replace the function f on a given interval with a quadratic function that shared three values with the function f. In so doing, he guaranteed that this new approximation rule would be exact for the definite integral of any quadratic polynomial. In one of the pleasant surprises of numerical analysis, it turns out that even though it was designed to be exact for quadratic polynomials, Simpson’s Rule is exact for any cubic polynomial: that is, if we are interested in an integral such as 25(5x32x2+7x4)dx, S2n will always be exact, regardless of the value of n. This is just one more piece of evidence that shows how effective Simpson’s Rule is as an approximation tool for estimating definite integrals.
 5 
One reason that Simpson’s Rule is so effective is that S2n benefits from using 2n+1 points of data. Because it combines Mn, which uses n midpoints, and Tn, which uses the n+1 endpoints of the chosen subintervals, S2n takes advantage of the maximum amount of information we have when we know function values at the endpoints and midpoints of n subintervals.

Subsection 5.6.5 Summary

  • For a definite integral such as 01ex2dx when we cannot use the First Fundamental Theorem of Calculus because the integrand lacks an elementary algebraic antiderivative, we can estimate the integral’s value by using a sequence of Riemann sum approximations. Typically, we start by computing Ln, Rn, and Mn for one or more chosen values of n.
  • The Trapezoid Rule, which estimates abf(x)dx by using trapezoids, rather than rectangles, can also be viewed as the average of Left and Right Riemann sums. That is, Tn=12(Ln+Rn).
  • The Midpoint Rule is typically twice as accurate as the Trapezoid Rule, and the signs of the respective errors of these rules are opposites. Hence, by taking the weighted average S2n=2Mn+Tn3, we can build a much more accurate approximation to abf(x)dx by using approximations we have already computed. The rule for S2n is known as Simpson’s Rule, which can also be developed by approximating a given continuous function with pieces of quadratic polynomials.

Exercises 5.6.6 Exercises

1.

Calculate the integral approximations T6 , M6 and S12 for
02x6dx.
T6 =
M6 =
S12 =

2.

Estimate 06x3dx using SIMP(4).
06x3dx

3.

Note: for this problem, because later answers depend on earlier ones, you must enter answers for all answer blanks for the problem to be correctly graded. If you would like to get feedback before you completed all computations, enter a "1" for each answer you did not yet compute and then submit the problem. (But note that this will, obviously, result in a problem submission.)
(a) What is the exact value of 04exdx?
04exdx=
(b)
Find LEFT(2), RIGHT(2), TRAP(2), MID(2), and SIMP(4); compute the error for each.
LEFT(2) RIGHT(2) TRAP(2) MID(2) SIMP(4)
value
error
(c)
Repeat part (b) with n=4 (instead of n=2).
LEFT(4) RIGHT(4) TRAP(4) MID(4) SIMP(8)
value
error

4.

Using the figure showing f(x) below, order the following approximations to the integral 03f(x)dx and its exact value from smallest to largest.
(Click on the graph for a larger version.)
Enter each of "LEFT(n)", "RIGHT(n)", "TRAP(n)", "MID(n)" and "Exact" in one of the following answer blanks to indicate the correct ordering:
< < < <

5.

Consider the definite integral 01xtan(x)dx.
  1. Explain why this integral cannot be evaluated exactly by using either u-substitution or by integrating by parts.
  2. Using appropriate subintervals, compute L4, R4, M4, T4, and S8.
  3. Which of the approximations in (b) is an over-estimate to the true value of 01xtan(x)dx? Which is an under-estimate? How do you know?

6.

For an unknown function f(x), the following information is known.
  • f is continuous on [3,6];
  • f is either always increasing or always decreasing on [3,6];
  • f has the same concavity throughout the interval [3,6];
  • As approximations to 36f(x)dx, L4=7.23, R4=6.75, and M4=7.05.
  1. Is f increasing or decreasing on [3,6]? What data tells you?
  2. Is f concave up or concave down on [3,6]? Why?
  3. Determine the best possible estimate you can for 36f(x)dx, based on the given information.

7.

The rate at which water flows through Table Rock Dam on the White River in Branson, MO, is measured in cubic feet per second (CFS). As engineers open the floodgates, flow rates are recorded according to the following chart.
Table 5.6.16. Water flow data.
seconds, t 0 10 20 30 40 50 60
flow in CFS, r(t) 2000 2100 2400 3000 3900 5100 6500
  1. What definite integral measures the total volume of water to flow through the dam in the 60 second time period provided by the table above?
  2. Use the given data to calculate Mn for the largest possible value of n to approximate the integral you stated in (a). Do you think Mn over- or under-estimates the exact value of the integral? Why?
  3. Approximate the integral stated in (a) by calculating Sn for the largest possible value of n, based on the given data.
  4. Compute 160Sn and 2000+2100+2400+3000+3900+5100+65007. What quantity do both of these values estimate? Which is a more accurate approximation?
You have attempted 1 of 6 activities on this page.