A Riemann sum to approximate the integral is given by , where represents the length of the interval [ ], is an arbitrary point in this interval, and the interval [ ] is divided up into n subintervals by the points < < ...< . If the lengths are all equal, so that , then we have a formula for the points: . If we further choose the points according to some reasonable scheme, then we obtain a formula which can be executed by the computer. For example, if we use left endpoints, then , or if we use right endpoints, then . The Trapezoid Rule is an average of these two methods, and usually gives a better approximation to the area than either one of these methods. Let us define both the left sums and the right sums in Maple.
We could define the Trapezoid Rule as just being the average of the left and right sum calculations, but we can also define it directly, according to the formula
It is not difficult to understand that this formula is based on the idea that if you add the left and right hand sums, each term in the sum is counted twice, except for the terms corresponding to and , which only occur once in the sum.Let us use this rule to compute the estimate for the area using . First we define the function and the endpoints, and then we can use the functions we have defined in Maple to estimate the area.
Let us compute the left sum, the right sum, their average, and the trapezoid approximation.
Notice that the trapezoid rule gives exactly the same answer as the average of the left hand and right hand sums.
For the function do the following.
Evaluate the integral in Maple, and get a floating point estimate for the answer.
Use the Trapezoid Rule with to estimate the integral.
Finally, find the error in the trapezoidal approximation.
2. The error in the Trapezoid Rule.
When is continuous on [ ], the error in the approximation of the integral using the Trapezoid Rule can be shown to satisfy the estimate
where is the length of a subinterval that the interval [ ] is partitioned into by subdividing into n parts, and M is any upper bound for the value of on this interval. The main difficulty in using this estimate of the error is finding a value of . If we use the ideas from calculus, we could find the maximum value of on this interval, and use this exact value of M to give an estimate of the maximum possible error. However, this depends on knowing the function exactly, and in applications that arise in practice, we usually only know the values of the function at certain points by experiment, so we use a more crude estimate for , taken deliberately to be larger than necessary in order to account for possible experimental error. Also, even if we know the function exactly, finding the upper bound exactly might be very difficult or impossible, so we rely on a choice of M which is easy to arrive at, but is probably larger than necessary.
For example, in Example 3 on page 398, the integral (which Maple can evaluate exactly) is studied. If we define
then we compute the second derivative
Now we could determine exactly where this function has a maximum or minimum on the interval [ ], but it is easy to see that we can choose as an upper bound. Let us define a function that will compute the error for the trapezoid rule, given an interval [ ] and an upper bound , as a function of the number of steps .
So for our function, we have
Suppose that we choose steps, then the estimate of the error is
If we choose steps, the error is less than
Finally, let us define the function, and use the Trapezoid Rule to estimate the integral.
Let us compare this with the value of the integral which Maple (and later in this course, you) can compute exactly.
The difference between the Trapezoid Rule and the calculated value of the integral is
Notice that this difference is smaller than our estimate of the error above.
Consider the function .
Use Maple to find a formula for the second derivative and simplify this formula.
On the interval [0,1], determine a value of M which is an upper bound for the absolute value of the second derivative.
Use this value of M to determine an error estimate for the Trapezoid Rule for .
Compare this value of the error to the actual error that you calculated in problem 1.
3. Simpson's Rule.
If you think about the idea behind the Trapezoid Rule, it consists of approximating the function by line segments going through the points [ ], and [ ], and computing the area under this approximating curve. The idea of Simpson's Rule is to use parabolas to approximate the function locally. For any three consecutive points on the curve, we can find a quadratic function that passes through these points, and find the integral of this quadratic approximation exactly. Each triple of points corresponds to two intervals if we chop the interval [ ] into smaller subintervals. Thus to use Simpson's rule, we need to divide the interval into an even number of smaller pieces, so we choose the number of steps to be an even number. The formula which is used to compute the estimate in Simpson's rule is given on page 400 of the text, and is a bit complicated to derive. It can be shown with some work that the formula below, which applies when n is even, is the result, called Simpson's Rule:
> ss:=n->1/3*(b-a)*(f(a)+f(b)+4*Sum(f(a+(2*i-1)*(b-a)/n),i = 1 .. 1/2*n)+2*Sum(f(a+2*(b-a)*i/n),i = 1 .. 1/2*n-1))/n;
Let us apply this rule to estimate the value of from example 4 on page 400 in the text. We will use .
Notice how close this estimate is to the real value, even though we used only a very small value of n .
For the function do the following.
First, evaluate the integral in Maple, and get a floating point estimate for the answer.
Next, use Simpson's Rule with to estimate the integral.
Find the error in the Simpson's Rule approximation.
Compare the error in Simpson's Rule with
to the error in the trapezoid rule with .
4. Estimating the error in Simpson's Rule.
When is continuous on [ ], the error in the approximation of the integral using Simpson's Rule can be shown to satisfy the estimate
where is the length of a subinterval that the interval [ ] is partitioned into by subdividing into n parts, and M is any upper bound for the value of on this interval. Just as in the case of the Trapezoid Rule, we use an upper bound M which is not the smallest value possible, but is one which can be found easily.
For example, suppose that we are considering the example from activity 3, the integral , which we estimate using Simpson's Rule. Let us first define the error estimate, like we did for the Trapezoid rule case.
Now, let us find an estimate for M .
Here, we can use the exact value of M =120 in the error estimate.
Notice that the error estimate is slightly larger than the actual error.
Consider the function .
Use Maple to find a formula for the fourth derivative and simplify this formula.
On the interval [0,1], determine a value of which is an upper bound for the absolute value of the second derivative.
Use this value of to determine an error estimate for Simpson's Rule for .
Compare this value of the error to the actual error that you calculated in activity 3.