8 Techniques of Integration

8.7 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 an antiderivative of the integrand. The second case is when we actually do not know the integrand, but only its value when evaluated at certain points.

An elementary function is any function that is a combination of polynomials, nth roots, rational, exponential, logarithmic and trigonometric functions and their inverses. 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:


The simplest way to refer to the antiderivatives of e-x2 is to simply write e-x2dx.

margin: y=e-x20.510.51xy y=sin(x3)-11-0.50.51xy y=sinxx510150.51xy Figure 8.7.1: Graphically representing three definite integrals that cannot be evaluated using antiderivatives. Λ

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:


as pictured in Figure 8.7.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]. We wish to approximate abf(x)dx. We partition [a,b] into n equally spaced subintervals, each of length Δx=b-an. The endpoints of these subintervals are labeled as


Section 5.3 showed that to use the Left Hand Rule we use the summation i=1nf(xi-1)Δx and to use the Right Hand Rule we use i=1nf(xi)Δx. We review the use of these rules in the context of examples.

Example 8.7.1 Approximating definite integrals with rectangles

Approximate 01e-x2dx using the Left and Right Hand Rules with 5 equally spaced subintervals.

SolutionWe begin by partitioning the interval [0,1] into 5 equally spaced intervals. We have Δx=1-05=1/5=0.2, so

x0=0,x1=0.2,x2=0.4,x3=0.6,x4=0.8, and x5=1.
margin: y=e-x20. y=e-x20. Figure 8.7.2: Approximating 01e-x2dx in Example 8.7.1 using (top) the left hand rule and (bottom) the right hand rule. Λ

Using the Left Hand Rule, we have:

i=1nf(xi-1)Δx =(f(x0)+f(x1)+f(x2)+f(x3)+f(x4))Δx

Using the Right Hand Rule, we have:

i=1nf(xi)Δx =(f(x1)+f(x2)+f(x3)+f(x4)+f(x5))Δx

Figure 8.7.2 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


The actual answer, accurate to 4 places after the decimal, is 0.7468, showing our average is a good approximation.

margin: xi Exact Approx. sin(xi3) x0 -π/4 -0.785 -0.466 x1 -7π/40 -0.550 -0.165 x2 -π/10 -0.314 -0.031 x3 -π/40 -0.0785 0 x4 π/20 0.157 0.004 x5 π/8 0.393 0.061 x6 π/5 0.628 0.246 x7 11π/40 0.864 0.601 x8 7π/20 1.10 0.971 x9 17π/40 1.34 0.690 x10 π/2 1.57 -0.670 Figure 8.7.3: Table of values used to approximate -π4π2sin(x3)dx in Example 8.7.2. Λ
Example 8.7.2 Approximating definite integrals with rectangles

Approximate -π4π2sin(x3)dx using the Left and Right Hand Rules with 10 equally spaced subintervals.

SolutionWe begin by finding Δx:


It is useful to write out the endpoints of the subintervals in a table; in Figure 8.7.3, we give the exact values of the endpoints, their decimal approximations, and decimal approximations of sin(x3) evaluated at these points.

margin: y=sin(x3)-11-0.50.51xyy=sin(x3)-11-0.50.51xy Figure 8.7.4: Approximating-π4π2sin(x3)dx in Example 8.7.2 using (top) the left hand rule and (bottom) the right hand rule. Λ

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(xi3) and multiplies the sum by Δx; the Right Hand Rule sums the last 10 values of sin(xi3) and multiplies by Δx. Therefore we have:

Left Hand Rule: -π4π2sin(x3)dx (1.91)(0.236)=0.451.
Right Hand Rule: -π4π2sin(x3)dx (1.71)(0.236)=0.404.

The average of the Left and Right Hand Rules is 0.4275. The actual answer, accurate to 3 places after the decimal, is 0.460. Our approximations were once again fairly good. The rectangles used in each approximation are shown in Figure 8.7.4. It is clear from the graphs that using more rectangles (and hence, narrower rectangles) should result in a more accurate approximation.

The Trapezoidal Rule

In Example 8.7.1 we approximated the value of 01e-x2dx with 5 rectangles of equal width. Figure 8.7.2 showed 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.

margin: y=e-x20. Figure 8.7.5: Approximating 01e-x2dx using 5 trapezoids of equal widths. Λ

Instead of using rectangles to approximate the area, we can instead use trapezoids. In Figure 8.7.5, we show the region under f(x)=e-x2 on [0,1] approximated with 5 trapezoids of equal width; the top “corners” of each trapezoid lie on the graph of f(x). It is clear from this figure that these trapezoids more accurately approximate the area under f and hence should give a better approximation of 01e-x2dx. (In fact, these trapezoids seem to give a great approximation of the area.)

margin: abh Figure 8.7.6: The area of a trapezoid is a+b2h. Λ

The formula for the area of a trapezoid is given in Figure 8.7.6. We approximate 01e-x2dx with these trapezoids in the following example.

Example 8.7.3 Approximating definite integrals using trapezoids

Use 5 trapezoids of equal width to approximate 01e-x2dx.

SolutionTo compute the areas of the 5 trapezoids in Figure 8.7.5, it will again be useful to create a table of values as shown in Figure 8.7.7.

margin: xi e-xi2 0 1 0.2 0.961 0.4 0.852 0.6 0.698 0.8 0.527 1 0.368 Figure 8.7.7: A table of values of e-x2. Λ

The leftmost trapezoid has legs of length 1 and 0.961 and a height of 0.2. Thus, by our formula, the area of the leftmost trapezoid is:


Moving right, the next trapezoid has legs of length 0.961 and 0.852 and a height of 0.2. Thus its area is:


The sum of the areas of all 5 trapezoids is:

+0.698+0.5272(0.2)+0.527+0.3682(0.2) =0.7445.

We approximate 01e-x2dx0.7445.

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 Δx=0.2. We can factor these coefficients out, leaving a more concise summation as:


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


This is the heart of the Trapezoidal Rule, where a definite integral abf(x)dx is approximated by using trapezoids of equal widths to approximate the corresponding area under f. Using n equally spaced subintervals with endpoints x0, x1, …, xn, we again have Δx=b-an. Thus:

abf(x)dx i=1nf(xi-1)+f(xi)2Δx
Example 8.7.4 Using the Trapezoidal Rule

Revisit Example 8.7.2 and approximate -π4π2sin(x3)dx using the Trapezoidal Rule and 10 equally spaced subintervals.

SolutionWe refer back to Figure 8.7.3 for the table of values of sin(x3). Recall that Δx=3π/400.236. Thus we have:

-π4π2 sin(x3)dx

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 xi and f(xi) 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.

We will also show that the Trapezoidal Rule makes using the Midpoint Rule obsolete as well. With much more work, it will turn out that the Midpoint Rule has only a marginal gain in accuracy. But we will include it in our results for the sake of completeness.

How can we improve on the Trapezoidal Rule, apart from using more and more trapezoids? The answer is clear once we look back and consider what we have really done so far. The Left Hand Rule is not really about using rectangles to approximate area. Instead, it approximates a function f with constant functions on small subintervals and then computes 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 computes the definite integral of this linear function. In both 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.

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 (x1,y1), (x2,y2) and (x3,y3) whose x-values are equally spaced and x1<x2<x3. Let f be the quadratic function that goes through these three points. An exercise will ask you to show that

x1x3f(x)dx=x3-x16(y1+4y2+y3). (8.7.1)
margin: 123123xy Figure 8.7.8: A graph of a function f and a parabola that approximates it well on [1,3]. Λ

Consider Figure 8.7.8. 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


Since g is a good approximation for f on [1,3], we can state that


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 abf(x)dx using Simpson’s Rule, subdivide [a,b] into n subintervals, where n is even and each subinterval has width Δx=(b-a)/n. We approximate f with n/2 parabolic curves, using Equation (8.7.1) to compute the area under these parabolas. Adding up these areas gives the formula:


Note how the coefficients of the terms in the summation have the pattern 1, 4, 2, 4, 2, 4, …, 2, 4, 1.

Let’s demonstrate Simpson’s Rule with a concrete example.

margin: xi e-xi2 0 1 0.25 0.939 0.5 0.779 0.75 0.570 1 0.368 (a)y=e-x20.250.50.7510.51xy (b) Figure 8.7.9: A table of values to approximate 01e-x2dx in Example 8.7.5, along with a graph of the function. Λ
Example 8.7.5 Using Simpson’s Rule

Approximate 01e-x2dx using Simpson’s Rule and 4 equally spaced subintervals.

SolutionWe begin by making a table of values as we have in the past, as shown in Figure 8.7.9(a). Simpson’s Rule states that


Recall in Example 8.7.1 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 8.7.9(b) shows f(x)=e-x2 along with its approximating parabolas, demonstrating how good our approximation is. The approximating curves are nearly indistinguishable from the actual function.

margin: xi sin(xi3) -0.785 -0.466 -0.550 -0.165 -0.314 -0.031 -0.0785 0 0.157 0.004 0.393 0.061 0.628 0.246 0.864 0.601 1.10 0.971 1.34 0.690 1.57 -0.670 (a)y=sin(x3)-11-0.50.51xy (b) Figure 8.7.10: A table of values to approximate -π4π2sin(x3)dx in Example 8.7.6, along with a graph of the function. Λ
Example 8.7.6 Using Simpson’s Rule

Approximate -π4π2sin(x3)dx using Simpson’s Rule and 10 equally spaced intervals.

SolutionFigure 8.7.10(a) shows the table of values that we used in the past for this problem, shown here again for convenience. Again, Δx=(π/2+π/4)/100.236.

Simpson’s Rule states that

-π4π2sin(x3)dx 0.2363[(-0.466)+4(-0.165)+2(-0.031)+

Recall that the actual value, accurate to 3 decimal places, is 0.460. Our approximation is within 0.01 of the correct value. The graph in Figure 8.7.10(b) shows how closely the parabolas match the shape of the graph.

Summary and Error Analysis

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

Key Idea 8.7.1 Numerical Integration

Let f be a continuous function on [a,b], let n be a positive integer, and let Δx=b-an. Set x0=a, x1=a+Δx, …, xi=a+iΔx, xn=b. Then abf(x)dx can be approximated by:
Left Hand Rule: Δx[f(x0)+f(x1)++f(xn-1)]. Right Hand Rule: Δx[f(x1)+f(x2)++f(xn)]. Midpoint Rule: Δx[f(x0+x12)+f(x1+x22)++f(xn-1+xn2)]. Trapezoidal Rule: Δx2[f(x0)+2f(x1)+2f(x2)++2f(xn-1)+f(xn)]. Simpson’s Rule: Δx3[f(x0)+4f(x1)+2f(x2)++4f(xn-1)+f(xn)] (n even).

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. (a)

    How was the “right” answer computed?

  2. (b)

    If the right answer can be found, what is the point of approximating?

  3. (c)

    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 8.7.1, we do not know the exact answer, but we know it starts with 0.7468. 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 8.7.1 states what these bounds are.

Theorem 8.7.1 Error Bounds in Numerical Integration

Suppose that Km is an upper bound on |f(m)(x)| on [a,b]. Then a bound for the error of the numerical method of integration is given by:

Method Error Bound
Left/Right Hand Rule K1(b-a)22n
Midpoint Rule K2(b-a)324n2
Trapezoidal Rule K2(b-a)312n2
Simpson’s Rule K4(b-a)5180n4

There are some key things to note about this theorem.

  1. (a)

    The larger the interval, the larger the error. This should make sense intuitively.

  2. (b)

    The error shrinks as more subintervals are used (i.e., as n gets larger).

  3. (c)

    When n doubles, the Left and Right Hand Rules double in accuracy, the Midpoint and Trapezoidal Rules quadruple in accuracy, and Simpson’s Rule is 16 times more accurate.

  4. (d)

    The error in Simpson’s Rule has a term relating to the 4th derivative of f. Consider a cubic polynomial: its 4th 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 8.7.3 and 8.7.5 and compute the error bounds using Theorem 8.7.1 in the following example.

Example 8.7.7 Computing error bounds

Find the error bounds when approximating 01e-x2dx using the Trapezoidal Rule and 5 subintervals, and using Simpson’s Rule with 4 subintervals.

SolutionTrapezoidal Rule with n=5:

We start by computing the 2nd derivative of f(x)=e-x2: margin: y=e-x2(4x2-2)0.51-2-1xy Figure 8.7.11: Graphing f′′(x) in Example 8.7.7 to help establish error bounds. Λ


Figure 8.7.11 shows a graph of f′′(x) on [0,1]. It is clear that the largest value of f′′, in absolute value, is 2. Thus we let M=2 and apply the error formula from Theorem 8.7.1.


Our error estimation formula states that our approximation of 0.7445 found in Example 8.7.3 is within 0.0067 of the correct answer, hence we know that


We had earlier computed the exact answer, correct to 4 decimal places, to be 0.7468, affirming the validity of Theorem 8.7.1.

Simpson’s Rule with n=4:

We start by computing the 4th derivative of f(x)=e-x2: margin: y=e-x2(16x4-48x2+12)0.51-5510xy Figure 8.7.12: Graphing f(4)(x) in Example 8.7.7 to help establish error bounds. Λ


Figure 8.7.12 shows a graph of f(4)(x) on [0,1]. It is clear that the largest value of f(4), in absolute value, is 12. Thus we let M=12 and apply the error formula from Theorem 8.7.1.


Our error estimation formula states that our approximation of 0.74683¯ found in Example 8.7.5 is within 0.00026 of the correct answer, hence we know that


Once again we affirm the validity of Theorem 8.7.1.

We have seen that, for 01e-x2dx, Simpson’s Rule with 4 subintervals is far more accurate than the Trapezoidal Rule with 5 subintervals. We now find how many intervals we would need to match that accuracy.

Example 8.7.8 Finding a number subintervals

Find the number of subintervals necessary to estimate 01e-x2dx to within 0.00026 using the Trapezoidal Rule.

SolutionWe can again use that f′′(x) is bounded by 2, so that


In order for this to be at most 0.00026, we need to have


Therefore, we will need at least 26 subintervals in order to have as much accuracy as Simpson’s Rule with 4 subintervals.

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 off of this data. We demonstrate this in an example.

Example 8.7.9 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 8.7.13. margin: Time Speed (min) (mph) 0 0 0.5 25 1 22 1.5 19 2 39 2.5 0 3 43 3.5 59 4 54 4.5 51 5 43 5.5 35 6 40 6.5 43 7 30 7.5 0 8 0 8.5 28 9 40 9.5 42 10 40 10.5 39 11 40 11.5 23 12 0 Figure 8.7.13: Speed data collected at 30 second intervals for Example 8.7.9. Λ Approximate the distance they traveled.

SolutionRecall that by integrating a speed function we get distance traveled. We have information about v(t); we will use Simpson’s Rule to approximate abv(t)dt.

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 30 second increments.

We need to compute Δx=(b-a)/n. Clearly, n=24. What are a and b? Since we start at time t=0, we have that a=0. The final recorded time came after 24 periods of 30 seconds, which is 12 minutes or 1/5 of an hour. Thus we have


Thus the distance traveled is approximately:

00.2v(t)dt 1360[f(x1)+4f(x2)+2f(x3)++4f(xn)+f(xn+1)]

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 8.7


Terms and Concepts

  1. 1.

    T/F: Simpson’s Rule is a method of approximating antiderivatives.

  2. 2.

    What are the two basic situations where approximating the value of a definite integral is necessary?

  3. 3.

    Why are the Left and Right Hand Rules rarely used?

  4. 4.

    Why is the Midpoint Rule rarely used?


In Exercises 5–12., a definite integral is given.

  1. (a)

    Approximate the definite integral with the Trapezoidal Rule and n=4.

  2. (b)

    Approximate the definite integral with Simpson’s Rule and n=4.

  3. (c)

    Find the exact value of the integral.

  1. 5.


  2. 6.


  3. 7.


  4. 8.


  5. 9.


  6. 10.


  7. 11.


  8. 12.


In Exercises 13–20., approximate the definite integral with the Trapezoidal Rule and Simpson’s Rule, with n=6.

  1. 13.


  2. 14.


  3. 15.


  4. 16.


  5. 17.


  6. 18.


  7. 19.


  8. 20.


In Exercises 21–24., find n such that the error in approximating the given definite integral is less than 0.0001 when using:

  1. (a)

    the Trapezoidal Rule

  2. (b)

    Simpson’s Rule

  1. 21.


  2. 22.


  3. 23.


  4. 24.


In Exercises 25–26., a region is given. Find the area of the region using Simpson’s Rule:

  1. (a)

    where the measurements are in centimeters, taken in 1 cm increments, and

  2. (b)

    where the measurements are in hundreds of yards, taken in 100 yd increments.

  1. 25.
  2. 26.
  1. 27.

    Let f be the quadratic function that goes through the points (x1,y1), (x1+Δx,y2) and (x1+2Δx,y3). Show that x1x1+2Δxf(x)dx=Δx3(y1+4y2+y3).

Omni CMS