Loading [MathJax]/jax/output/HTML-CSS/jax.js
Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts

4.4: Numerical Integration

( \newcommand{\kernel}{\mathrm{null}\,}\)

Motivating Questions
  • How do we accurately evaluate a definite integral such as 10ex2dx when we cannot use the First Fundamental Theorem of Calculus because the integrand lacks an elementary algebraic antiderivative? Are there ways to generate accurate estimates without using extremely large values of n in Riemann sums?
  • What is the Trapezoid Rule, and how is it related to left, right, and middle Riemann sums?
  • How are the errors in the Trapezoid Rule and Midpoint Rule related, and how can they be used to develop an even more accurate rule?

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

Ln=f(x0)Δx+f(x1)Δx++f(xn1)Δx=n1i=0f(xi)Δx,Rn=f(x1)Δx+f(x2)Δx++f(xn)Δx=ni=1f(xi)Δx,Mn=f(¯x1)Δx+f(¯x2)Δx++f(¯xn)Δx=ni=1f(¯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 4.4.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.

5_6_LRMsum.svg

Figure 4.4.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 the applet 1  at http://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.)

Marc Renault, Shippensburg University

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 4.4.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 30x2dx.

  1. Use the applet at http://gvsu.edu/s/a9 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.
  2. Likewise, use the applet to compute R3 and M3, the right and middle Riemann sums with three subintervals, respectively.
  3. Use the Fundamental Theorem of Calculus to compute the exact value of I=30x2dx.
  4. We define the error that results from an approximation of a definite integral to be the approximation's value minus the integral's exact value. What is the error that results from using L3? From R3? From M3?
  5. 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?
  6. Working by hand, estimate the area under f(x)=x2 on [0,3] using three subintervals and three corresponding trapezoids. What is the error in this approximation? How does it compare to the errors you calculated in (d)?

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 4.4.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.

5_6_TRAP.svg

Figure 4.4.2: Estimating baf(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 baf(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

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 ???, 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 baf(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.=(n1i=012(f(xi)+f(xi+1))Δx.

Moreover, Tn=12[Ln+Rn].

Activity 4.4.2

In this activity, we explore the relationships among the errors generated by left, right, midpoint, and trapezoid approximations to the definite integral 211x2dx.

  1. Use the First FTC to evaluate 211x2dx exactly.
  2. Use appropriate computing technology to compute the following approximations for 211x2dx: 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=T4211x2dx.

    Similarly, we compute the error of the midpoint rule approximation with 8 subintervals by the formula

    EM,8=M8211x2dx.

    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)?

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 baf(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 4.4.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.

5_6_MidVTrap.svg

Figure 4.4.3: Estimating baf(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 4.4.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 4.4.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.

5_6_MidTrapError.svg

Figure 4.4.4: Comparing the error in estimating baf(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 baf(x)dx, while Mn will underestimate baf(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 4.4.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 10f(x)dx, we know by the First FTC that the exact value of the integral is

10(1x2)dx=xx33|10=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 4.4.2, we find the results summarized in Table 4.4.5. We also include the approximations and their errors for the example 211x2dx from Activity 4.4.2.

Table 4.4.5: Calculations of T4, M4, T8, and M8, along with corresponding errors, for the definite integrals 10(1x2) dx and 211x2 dx.
Rule 10(1x2)dx=0.¯6 error 211x2dx=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=T4baf(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 4.4.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.

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 baf(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

S2n=2Mn+Tn3.

The rule for S2n giving by Equation ??? is usually known as Simpson's Rule. 2  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 4.4.5 to see the approximations generated by Simpson's Rule. In particular, in Table 4.4.6, we include all of the results in Table 4.4.5, but include additional results for S8=2M4+T43 and S16=2M8+T83.

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.
Table 4.4.6: Table 4.4.5 updated to include S8, S16, and the corresponding errors.
Rule 10(1x2)dx=0.¯6 error 211x2dx=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 4.4.6 are striking. If we consider the S16 approximation of 211x2dx, 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 10(1x2)dx is zero! 3 

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 10ex2dx, 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 4.4.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.

Table 4.4.7 Data for the braking car.
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
5_6_Act2.svg
Figure 4.4.8: Axes for plotting the data in Activity 4.4.3.
  1. Plot the given data on the set of axes provided in Figure 4.4.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?

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 4.4.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 4.4.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 10f(x)dx, 10g(x)dx, and 10h(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 10f(x)dx, 10g(x)dx, and 10h(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?

5_6_Act3.svg

Figure 4.4.9: Axes for plotting the functions in Activity 4.4.4.

The results seen in Activity 4.4.4 generalize nicely. For instance, if f is decreasing on [a,b], Ln will over-estimate the exact value of baf(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 52(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. 4 

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.

Summary

  • For a definite integral such as 10ex2dx 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 baf(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 baf(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.

This page titled 4.4: Numerical Integration is shared under a CC BY-SA 4.0 license and was authored, remixed, and/or curated by Matthew Boelkins, David Austin & Steven Schlicker (ScholarWorks @Grand Valley State University) via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?