< previous page page_552 next page >

Page 552
Output: The input data (echo-print) and the value calculated for the area over the given interval.
Discussion: Our approach is to compute an approximation to this area. If the area under the curve is divided into equal, narrow, rectangular strips, the sum of the areas of these rectangles is close to the actual area under the curve (see Figure 10-7). The narrower the rectangles, the more accurate the approximation should be.
We can use a value-returning function to compute the area of each rectangle. The user enters the low and high values for X, as well as the number of rectangles into which the area should be subdivided (divisions). The width of a rectangle is then
(high - low) / divisions
The height of a rectangle equals the value of X3 when X is at the horizontal midpoint of the rectangle. The area of a rectangle equals its height times its width. Because the leftmost rectangle has its midpoint at
(low + width/2.0)
0552-01.gif
Figure 10-7
Approximation of Area Under a Curve

 
< previous page page_552 next page >