If you were to do a bit of experimentation, you would see that using rectangles
is not always the most effective way to approximate the area under a curve.
One simple improvement that we can make to obtain better approximations is to
estimate the area under a curve by using a series of trapezoids instead
of rectangles. See this for an illustration.
As before, we divide the interval (a, b) into N equal subintervals, each of
size
Also as before the endpoints of the ith subinterval are a+(i-1)h and a+ih.
The (x,y)-coordinates of the four corners of the trapezoid that we use to
approximate the area under the curve in this subinterval are then
- (a+(i-1)h, 0) (the lower-left corner)
- (a+(i-1)h, f(a+(i-1)h)) (the upper-left corner)
- (a+ih, 0) (the lower-right corner)
- (a+ih, f(a+ih)) (the upper-right corner)
The area of this trapezoid is given by the length of the base times the average
of the heights of the two sides:
Now to approximate the area under the curve, we simply add up the areas of all
of the trapezoids:
If you think about what is going on in this summation, you can come up with
a new summation that can be computed more efficiently. Except for f(a) and
f(b), every other value of f that is computed in this summation is computed
twice. Why is that?
Click here for the answer
Based upon this realization, it is not difficult to come up with a summation
that requires half as much work to compute:
Christopher R. Johnson
Hamlet Project
Department of Computer Science
University of Utah