Mathematics 161                                  Laboratory 11                           November 12, 1992
	  
Name: _____________________________   Lab Partner: ___________________________
	  
Consulted with:  ____________________________________________________________

© Lafayette College, 1994

Area of a Region with Curved Boundary

This laboratory is designed to give you experience with numerical estimation of area.

Part 0:  The Region of Interest

Preliminaries

As in preceding labs, we will use some special commands.  They are in a new package called "IntegralGraphics." We input the package as follows:

<<i:\course\root\math161\integral.m

Hard Copy

Consider the region which lies under the graph of f(x) = 1/x, above the x-axis, and between the x values a = 1.0 and b = 2.0.  The command below defines f, a, and b, and plots the graph of f(x).  Print out the graph and shade in the region described.  In this lab we aim to estimate the area of this region to about ten decimal place accuracy with little computer time—no more than ten seconds.

a = 1.0;
b = 2.0;
f[x_] := 1/x;
Plot[f[x], {x,0.01,3}, PlotRange->{0,2}];

Skinny Rectangles

The idea we use is that the area under the curve (which has an "irregular" top) can be approximated by the sum of the areas of "skinny rectangles" (which have flat tops, and therefores areas easy to compute).  To see how this works, look at the curve and a suitable group of rectangles.  The command:

leftrect[f[x], {x, a, b, 10}];

plots the graph of f(x) over the relevant region along with a ten-rectangle approximation to the area under the curve.  The rectangles take their height from the value of the function at the left endpoint of their base.  As a result, the sum of the area of the rectangles overestimates the area.  If we use more rectangles, as in the following command:

leftrect[f[x], {x, a, b, 25}];

then the error in our estimation by summing of the areas of the rectangles is still larger than the area of the region.  Suppose we take the rectangle's height from the function value at the right endpoint of the base, then we would have an underestimation of the region's area, as the following plot shows:

rightrect[f[x], {x, a, b, 10}];

In what follows, you will investigate the algebra of actually summing these sorts of estimates, and investigate the actual errors involved.

Complete Part 1 before starting Part 2.

Part 1: Left and Right Endpoints

Let's begin by finding the area estimate given by the first plot we generated. The width of each rectangle in the plot is

h = (b - a)/10.0

while the height of the nth rectangle is f(a + (n – 1)h).  So the sum of the areas is

The Mathematica notation for this summation is:

Sum[h f[a + (n - 1)h],{n, 1, 10}]

Modify these commands (the definition of h and the summation above) to find the area estimate given by the 25 rectangle approximation.  Try a 100 rectangle approximation next.  Write your estimates below:

        Using 10 rectangles we estimate the area to be:  _____________
        
        Using 25 rectangles we estimate the area to be:  _____________
        
       Using 100 rectangles we estimate the area to be: _____________

To automate this process, define h to be a function of the number of rectangles as follows

Clear[h];
h[nrec_] := (b - a)/nrec

and the area estimate using rectangles with height taken at their left endpoints is

leftest[nrec_] := Sum[h[nrec]f[a + (n-1)h[nrec]],{n,1,nrec}]

Verify that this function gives the same estimates you found above.

Modify the definition of leftest to define a new function rightest that estimates the area of the region using rectangles with height taken at the right endpoint.  Write your definition here.

Use rightest to obtain area estimates using 10, 25, and 100 rectangles, and write them below:

        Using 10 rectangles we estimate the area to be:  _____________
        
        Using 25 rectangles we estimate the area to be:  _____________
        
       Using 100 rectangles we estimate the area to be: _____________

Do the estimates obtained thus far agree with our insight in Part 0 that left-endpoint estimates overestimate the area and right-endpoint estimates underestimate it?  Explain.

To compute the error in a given estimate of the area of the region we are considering, use a special function defined in the IntegralGraphics package:  error[estimate] gives the error in the estimate estimate to the area of the region.  Use this function to compute the errors in the following table:

Left endpoint              Right endpoint

Error in 10 rectangle estimate:   ____________              _____________

Error in 25 rectangle estimate:   ____________              _____________

Error in 100 rectangle estimate: ____________              _____________

Have any of our estimates thus far achieved ten decimal place accuracy?

At best, how many decimal places are correct?

How does the error in leftest change as the
number of rectangles is increased by a factor of ten?

Based on the information you have, estimate how many
rectangles must be used to obtain ten place accuracy:

Could your computer perform the necessary computation in ten seconds?

The error table verifies that the left- and right-endpoint methods over- and under-
estimate respectively.  Given that this is the case, how can we combine these two estimates to arrive at a better estimate?

Part 2:  Approximations using Trapezoids

One answer to the last question is to average the estimates given by leftest and rightest.  Geometrically, this is like replacing the rectangles in Part 1 with trapezoids.  We can implement this averaging with

trap[nrec_] := (leftest[nrec] + rightest[nrec])/2.

View this graphically for 10 subdivisions (now trapezoids, not rectangles) with

trapezoid[f[x], {x, a, b, 10}];

From the plot, does this appear to be a more promising technique? Explain.

Estimate the area by using trap with nrec = 10, 100, 1000.  What are the errors in these estimates?

                                           Area estimate           Error in estimate

Using 10 trapezoids:      _____________         _______________

Using 100 trapezoids:    _____________         _______________

Using 1000 trapezoids:  _____________         _______________

How does the error of trap change as the number of subdivisions is increased by a factor of ten?

Would it be possible to estimate the area to the desired 10 decimal places with this method using ten seconds or less of computer time?

Part 3:  Midpoints

Now define another rectangle method.  This time, let the rectangle heights be given by the values of the function at the midpoints of the subintervals.  To see how this will work, use the following command:

midrect[f[x], {x,a,b,10}]

From the plot, do you think that the midpoint method will provide better or worse estimates than a comparable number of trapezoids?  Explain.

Define a function mid[nrec] to estimate the sum of the areas of these rectangles.  Give your definition of mid here:

Estimate the area by using mid with nrec = 10, 100, 1000.  What are the errors in these estimates?

Area estimate           Error in estimate

Using 10 rectangles:      _____________         _______________

Using 100 rectangles:    _____________         _______________

Using 1000 rectangles:  _____________         _______________

How does the error of mid change as the number of subdivisions is increased by a factor of ten?

Part 4:  An Improved Method

Make a careful comparison of the errors you found using trap and mid. A table like that at the end of Part 1 might be helpful. Find a way to combine trap and mid to get better estimates for the desired area.  Write a definition for your new rule here.



How does the error of this method change as the subinterval width is decreased by a factor of ten?

How many seconds (approximately) does this method take to compute an estimate accurate to 10 decimal places?  What step size did you use for that estimate?