Numerical Integration

Return to Main Page
Index of OnLine Topics Exercises for This Topic Everything for Calculus Utility: Numerical Integration Utility TI83: Graphing Calculator Programs 
The Fundamental Theorem of Calculus gives us an exact formula for computing _{}_{a}^{b}f(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 _{}_{a}^{b}f(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  = 


= 


= 

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  = 


= 


= 

The right Riemann sum gives the area shown below.
_{}
Example 1 Computing Left and Right Riemann Sums
Let f(x) = 1  x^{2}. Compute the left and right Riemann sum approximations of _{}_{0}^{1}f(x) dx with n = 8.
Solution
The left Riemann sum for the function is illustrated here:
To compute it, we use the following setup:
A trapezoid is a foursided 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.
Leftmost trapezoid:  1 2  (f(x_{0}) + f(x_{1}))x  Average height width 
Next trapezoid:  1 2  (f(x_{1}) + f(x_{2}))x  
. . .  
Last trapezoid:  1 2  (f(x_{n1}) + f(x_{n}))x  
Adding these together, gives the trapezoid sum:
Trapezoid Sum  = 

Simplifying gives
Trapezoid Sum The trapezoid approximation of _{}_{a}^{b}f(x) dx associated with the partition a = x_{0} < x_{1} < ... < x_{n} = b is given by

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 _{}_{0}^{1}(1x^{2}) dx with n = 8.
Solution
In view of the comment immediately above, we have already computed it, in effect:
Trapezoid Sum  =  Average of Left and Right Riemann Sums  
=  2  =  0.6640625 
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 _{}_{1}^{2}e^{x2 } dx with n = 4.
Solution
Since n = 4, the width of the subintervals is (ba)/4 = (21)/4 = 0.25.
Now proceed as follows using the table below:
1. Enter the correct partition values (x_{0}, s_{1}, ... ).
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(x_{i}) and to complete the table.
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 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, x_{k} = a + kx = a + k (ba)/n, then

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 (x_{k1}, f(x_{k1})), (x_{k}, f(x_{k})), and (x_{k+1}, f(x_{k+1})), as shown in the figure.
It is then not too difficult to find the equation of this parabola (it has the form y = Ax^{2}+Bx+C), and from that to find the area underneath by integrating. The remarkably simple answer is
Area under parabola  =  3n 
[f(x_{k1}) + 4f(x_{k}) + f(x_{k+1})]. 
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 _{}_{0}^{1} x^{2} dx.
Solution
Since n = 4, we have (ba)/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 _{}_{0}^{6}e^{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.)
x  0  1  2  3  4  5  6 
f(x) = e^{x2}  1  0.367879  0.018316  0.000123  0  0  0 
4  2  4  2  4  
1  1.471518  0.036631  0.000494  0  0  0 
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
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
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 _{}_{1}^{2}e^{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 32x^{2} = 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  1  1.225  2 
f"(x)  0.74  0.90  0.26 
The largest value of f"(x) is therefore 0.90. This tells us that the error is no larger than
124^{2} 
0.0047 
_{}
Example 7 Estimating the Error in the Simpson Sum
How large would n have to be to obtain a Simpson rule approximation of _{}_{1}^{2}(x^{3} + 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
Error  180n^{4} 
f^{(4)}(M) 
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
Error  180n^{4} 
f^{(4)}(M)  
<  180n^{4}  3  =  20n^{4}  . 
We would loke this quantity to be at most 0.000 005 for a suitable n. To find n, we can set 81/20n^{4} 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 OnLine Topics Exercises for This Topic Everything for Calculus Utility: Numerical Integration Utility TI83: Graphing Calculator Programs 