Numerical Integration
miscellaneous on-line topics for
Calculus Applied to the Real World

              Return to Main Page
Index of On-Line Topics
Exercises for This Topic
Everything for Calculus
Utility: Numerical Integration Utility
TI-83: Graphing Calculator Programs

The Fundamental Theorem of Calculus gives us an exact formula for computing abf(x) dx, provided we can find an antiderivative for f. This method of evaluating definite integrals is called the analytic method. However, there are times when this is difficult or impossible. In these cases, it is usually good enough to find an approximate, or numerical solution, and there are some very straighforward ways to do this.

The simplest numerical approximations to the integral are the left and right Riemann sums. More efficient approximations (below) are the trapezoidal and Simpson approximations.

Left and Right Riemann Sums
All numerical approximations of the integral abf(x) dx we will consider start with a partition of the interval [a. b] into n equal parts:

In Calculus Applied to the Real World, we defined the left Riemann sum as follows:

Left Riemann Sum =
n-1

n = 0
f(xk)x
=
f(x0)x + f(x1)x + ... + f(xn-1)x
=
[f(x0) + f(x1) + ... + f(xn-1)]x

The left Riemann sum gives the area shown below.

Notice that the left side of each rectangle matches the height of the graph -- hence the name "left sum." The right Riemann sum is defined similarly:

Right Riemann Sum =
n

n = 1
f(xk)x
=
f(x1)x + f(x2)x + ... + f(xn)x
=
[f(x1) + f(x2) + ... + f(xn)]x

The right Riemann sum gives the area shown below.

 
Example 1 Computing Left- and Right Riemann Sums

Let f(x) = 1 - x2. Compute the left and right Riemann sum approximations of 01f(x) dx with n = 8.

Solution

The left Riemann sum for the function is illustrated here:

To compute it, we use the following setup:

We now calcuate the partition values in the following table.

x0 = a
x1 = a+x
x2 = a+2x
x3 = a+3x
x4 = a+4x
x5 = a+5x
x6 = a+6x
x7 = a+7x
x8 = b =
 
 
 
 
 
 
 
 
 

 
 

x
x0
x1
x2
x3
x4
x5
x6
x7
x8
Value
f(x) = 1-x2


 

We can now compute the left- and right Riemann sums as follows:


Trapezoid Sums

A trapezoid is a four-sided region with two opposite sides parallel. In the figure below, it is the two vertical sides that are parallel.

The area of a trapezoid is the average length of the parallel sides, times the distance between them.

Given a partition of [a, b] as above, we can define the associated trapezoid sum to correspond to the area shown below.

The areas of the individual trapezoids (from left to right) are as follows.

Adding these together, gives the trapezoid sum:

Trapezoid Sum =
1

2
(f(x0) + f(x1))x + 1

2
(f(x1) + f(x2))x + . . . + 1

2
(f(xnÁ1) + f(xn))x

Simplifying gives

Trapezoid Sum

The trapezoid approximation of abf(x) dx associated with the partition a = x0 < x1 < ... < xn = b is given by

    Trapezoid Sum=
    1

    2
    [f(x0) + 2f(x1) + ... + 2f(xn-1) + f(xn)]x

 
If you look carefully at the above formula, you will see that the trapezoid sum is just the average of the left- and right Riemann sums.

 
Example 2 Computing a Trapezoid Sum

Compute the trapezoid sum approximation of 01(1-x2) dx with n = 8.

Solution

In view of the comment immediately above, we have already computed it, in effect:



 

Q How about computing the trapezoid sum without first computing the left- and right Riemann sums?
A Here is an example.

 
Example 3 Computing a Trapezoid Sum

Compute the trapezoid sum approximation of 12e-x2 dx with n = 4.

Solution

Since n = 4, the width of the subintervals is (b-a)/4 = (2-1)/4 = 0.25.

Now proceed as follows using the table below:

1. Enter the correct partition values (x0, s1, ... ).
2. Entering the correct formula for f(x) (graphing calculator format). (This is similar to what you would do using on a graphing calculator or spreadsheet. Here are some examples of correctly formatted expressions.)
3. Press "Compute" to obtain the values of f(xi) and to complete the table.

x
x0 = a
x1
x2
x3
x4
   
 
 
 
 
Enter Formula Here:
f(x) =

2 2 2
Total:

 

We can now compute the Trapezoid sum as follows:

Before we go on...

To automate the entire calculation, or to use much larger values of n, try our Numerical Integration Utility.


Simpson's Rule

Simpson's rule is another approximation of the integral. Again, we start by partitioning [a, b] into intervals all of the same width, but this time we must use an even number of intervals, so n will be even.

Simpson's Rule

If n is even, and, as before, xk = a + kx = a + k (b-a)/n, then

    b
     
     
    a
    f(x) dx
    b - a

    3n
    [f(x0) + 4f(x1) + 2f(x2) + 4f(x3) + ... + 2f(xn-2) + 4f(xn-1) + f(xn)]

 

Q Why?
A As with the trapezoid rule, we want to approximate the areas in each strip by something more complicated than a rectangle. This time we take the strips in pairs (which is why we need an even number of them) and draw a parabola through the three points (xk-1, f(xk-1)), (xk, f(xk)), and (xk+1, f(xk+1)), as shown in the figure.

It is then not too difficult to find the equation of this parabola (it has the form y = Ax2+Bx+C), and from that to find the area underneath by integrating. The remarkably simple answer is

When we add the area under the parabola over the first two strips to the area under the parabola over the 3rd and 4th strips, and so on, we get Simpson's rule.

 
Example 4 Simpson's Rule

Use 4 intervals in Simpson's rule to approximate 01 x2 dx.

Solution

Since n = 4, we have (b-a)/n = 1/4, and Simpson's rule tells us that

Before we go on...

This is the exact answer. What is going on? Remember that Simpson's rule is based on approximating the graph by quadratic functions. If the function is already quadratic, as it is here, the approximation is exact.


 
Example 5 Simpson's Rule

Use 6 intervals in Simpson's rule to approximate 06e-x2 dx. (We already approximated a similar integral using the trapezoid rule here.)

Solution

The following table summarizes the main part of the computation. (Figures are rounded to 6 decimal places.)

x0123456
f(x) = e-x210.3678790.0183160.000123000
42424
11.4715180.0366310.000494000


Accuracy of Trapezoid and Simpson Approximations

If you look at the diagrams above, you will see that the approximations we have been using become more accurate as the number of subdivisions n gets larger. This raises an interesting and important question: How large does n have to be to get "close enough" to the right answer? To answer these questions, we need to know something about the error in these two rules, that is, how far they are from the right answer.

 
Q Doesn't this raise a "Catch 22" situation? In order to know the error, we need to know the exact answer. But if we knew the exact answer, then we would hardly need to find a numerical approximation in the first place!
A We remedy this dilemma as follows: since we can't always calculate exactly what the error is, we look instead for a bound on the error. For instance, instead of trying to say "the error is exactly 0.001," we say instead, "the error is no larger than 0.001."

The following formulas give bounds on the errors for the rules we have been using.

The Errors in the Trapezoid Rule and Simpson's Rule

If f"(x) is continuous in [a, b], then the error in the trapezoid rule is no larger than

    (b - a)3

    12n2
    |f"(M)|,

where |f"(M)| is the largest value of |f" (x)| in [a, b].


If f(4)(x) is continuous in [a, b], then the error in Simpson's rule is no larger than

    (b - a)5

    180n4
    |f(4)(M)|,

where |f(4)(M)| is the largest value of |f(4)(x)| in [a, b].

 
Example 6 Estimating the Error in the Trapezoid Sum

How accurate is the calculation in Example 3?

Solution

In that example we used 4 intervals in the trapezoid rule to estimate 12e-x2 dx

In order to estimate the error, we need to find the largest value of |f" (x)| in the interval [1, 2]. for f(x) = e-x2.

Calculating,

Since we want to find the extreme values of f", we calculate its derivative,

Now f(3)(x) = 0 only when x = 0 or 3-2x2 = 0, so x = 0 or ▒ (3/2)1/2 ▒1.225. Checking values in the interval [1, 2], we get the following (where we have rounded up the values of f"(x) rather than simply rounding to two decimal places (why?).

x 11.2252
f"(x)0.740.900.26

The largest value of |f"(x)| is therefore 0.90. This tells us that the error is no larger than


 
Example 7 Estimating the Error in the Simpson Sum

How large would n have to be to obtain a Simpson rule approximation of -12(x3 + e-x) dx accurate to five decimal places?

Solution

"Accurate to 5 decimeal places" means an error of less than 0.000 005. In this problem, we don't know the value of n, but we do know an upper bound for the error.

Our formula for the error in Simpson's rule says that

A quick calculation shows that the 4th derivative of f is

so that it is positive, and its larest value in the interval [-1, 2]occurs when x = -1:

As before, we have overestimated rather than underestimated the quantity e (never underestimate an error!). This gives

We would loke this quantity to be at most 0.000 005 for a suitable n. To find n, we can set 81/20n4 equal to 0.000 005 and solve for n, and then round up to the nearest integer. We obtain:.


 

Return to Main Page
Index of On-Line Topics
Exercises for This Topic
Everything for Calculus
Utility: Numerical Integration Utility
TI-83: Graphing Calculator Programs

Last Updated: September, 1999
Copyright © 1999 Stefan Waner & Steven R. Costenoble