Lab 3

advertisement
Lab 3: Numerical Integration
Seattle Pacific University, MAT 1235, Calculus II
Objectives


To understand the geometry behind two methods of numerical integration: the trapezoid
rule and Simpson’s rule.
To gain a feel for the relative speeds of convergence of Riemann sums, trapezoid rule,
and Simpson’s rule.
Due Date: Monday 02/22 2:00 p.m.

Do not wait until the last minute to finish the lab. You never know what technical
problems you may encounter (no papers in the printer, electricity is out, your best
friend call and talk for 4 hours, alien attack…etc).
Name 1:
Name 2:
Date:
The original version of this lab was adapted by Brian Gill and the SPU mathematics department from Lab 16
(Exploring Exponentials, by Robert Messer) in Learning by Discovery: A Lab Manual for Calculus, Anita Solow,
editor, 1993. The book is volume 27 of the MAA Notes series published by the Mathematical Association of
America.
Suppose we want to calculate a definite integral
 f  x  dx .
b
a
The Fundamental Theorem of
Calculus states that
 f  x  dx  F b   F  a  ,
b
a
where F is any antiderivative of f. However, integrals such as

 2
0
cos x dx and

1
0
1  9 x4 dx
give us problems because we cannot find usable expressions for the antiderivative of the
integrands. In this lab, we will look at three methods for numerically approximating the value of
a definite integral: Riemann sums, the trapezoid rule, and Simpson’s rule.
Maple Commands
b
Here is a list of Maple commands that perform numerical approximation of
 f ( x)dx .
a
We first load the student package by typing
>with(student):
It has the commands that we need in this lab.
Riemann Sums, using left endpoints as the sample points, with n subintervals
>evalf(leftsum(f(x),x=a..b,n));
Trapezoidal Rule with n subintervals
>evalf(trapezoid(f(x),x=a..b,n));
Simpson’s Rule with n subintervals
>evalf(simpson(f(x),x=a..b,n);
2
Lab Exercises
1. In this lab, we will compare several methods for providing numerical estimates for the value
of the integral
  5x
1
0
Use Maple to find the numerical value of
4
 3x2  1 dx .
  5x
1
0
4
 3x2  1 dx .
1
∫ (5𝑥 4 − 3𝑥 2 + 1)𝑑𝑥 =
0
Riemann Sums
One approach that you have seen in the definition of a definite integral is to form a Riemann
sum. In this method, we approximate the area under the curve y  f  x  , a  x  b , by using
the sum of the areas of some rectangles. In Figure 1 we have a picture of a Riemann sum
using four subintervals of equal length, with the height of each rectangle being the value of the
function at the left-hand endpoint of that subinterval.
Figure 1: Riemann Sum
3
2.
a. Use a Riemann sum with n = 4 subintervals to approximate
  5x
1
0
4
 3x2  1 dx . Use the
left endpoints as the sample points.
Compute the error in your approximation (that is, find the absolute value of the difference
between your approximation and the actual value of the definite integral).
b. Use Maple to approximate the same integral with n = 16 subintervals. Calculate the error
in the approximation.
c. Experiment with Maple to find a value for n so that the Riemann sum gives an answer that
is accurate to within .001 of the actual value of the integral (try to find the smallest value
of n that will make the error in the approximation .001 or less).
Use the following table to record your data.
Method Used
Number of
Subintervals
Approximation to the
Integral
(10 decimal places)
Error in
Approximation
(10 decimal places)
Width of each
Subinterval
Left Riemann
Sum
Left Riemann
Sum
Left Riemann
Sum
4
Trapezoid Rule
In Riemann sums, we replace the area under the curve by the area of rectangles. However, the
corners of the rectangles tend to stick out, and the tops of the rectangles do not do a particularly
good job of following along the actual curve. Another method is to use trapezoids instead of
rectangles to estimate the area, as illustrated in Figure 2. The trapezoids tend to more closely
follow the actual shape of the curve than rectangles, so we might expect to get more accurate
estimates using this method.
Figure 2: Trapezoid Rule
Figure 3
3. a. Determine the area of the trapezoid in Figure 3. Explain carefully with the help of a
diagram. (Hint: break up the trapezoid into a triangle and a rectangle.)
5
b. Apply this formula four times to the four trapezoids shown in Figure 2. Let T4 denote the
sum of the area of the four Trapezoids. Show the algebra necessary to get that
T4 
where x 
x
 f  x0   2 f  x1   2 f  x2   2 f  x3   f  x4   ,
2 
b  a x4  x0
.

4
4
c. If we used n equally spaced trapezoids rather than 4, we let Tn be the sum of the areas of the
n trapezoids. Derive a formula for Tn .
6
d. Repeat Exercise 2 using the trapezoid rule and record your data in the table.
Use the following table to record your data.
Method Used
Number of
Subintervals
Approximation to the
Integral
(10 decimal places)
Error in
Approximation
(10 decimal places)
Width of
each
Subinterval
Trapezoid Rule
Trapezoid Rule
Trapezoid Rule
Simpson’s Rule
In the trapezoid rule, we replaced pieces of the curve by straight lines. In Simpson’s rule, we
replace pieces of the curve by parabolas in hopes that the curved parabolas will provide even
better approximations that the straight lines from the trapezoid rule. To approximate
 f  x  dx
b
a
, we divide  a, b into n subintervals of equal length, where n is even. Simpson’s rule depends
on the fact that there is a unique parabola through any three points on a curve. A picture of the
parabolas used for Simpson’s rule where n = 4 is shown in Figure 4. The dashed curve is the
parabola through  x0 , f  x0   ,  x1 , f  x1   , and  x2 , f  x2   , while the dotted curve is the
parabola through  x2 , f  x2   ,  x3 , f  x3   , and  x4 , f  x4   . The details are messy, but the area
under the parabola through  x0 , f  x0   ,  x1 , f  x1   , and  x2 , f  x2   can be shown to be
x
b  a x4  x0

 f  x0   4 f  x1   f  x2   , where x 
.

3
4
4
Figure 4: Simpson’s Rule
7
4. Repeat Exercise 2 using Simpson’s rule, again recording your data in the table.
Use the following table to record your data.
Method Used
Number of
Subintervals
Approximation to the
Error in
Integral
Approximation
(10 decimal places) (10 decimal places)
Width of each
Subinterval
Simpson’s Rule
Simpson’s Rule
Simpson’s Rule
5. What value of n did you need for each method to get the answer accurate to within .001 of the
actual value of the integral? Which method needed the smallest value of n? (We call this the
fastest method since fewer computations are required with smaller values of n.) Which
needed the largest n? (This is the slowest method.)
8
Download