[previous] [up] [next]     [index]
Next: The Slope of a Up: Mathematical Examples Previous: Taylor Series

The Area Under a Function

Consider the function graph in figure [cross-reference]. Suppose we wish to know the area between the x axis, the fat lines labeled a and b, and the graph. Determining the area under the graph of a function for some specific interval is called integrating a function. Since engineers had to solve this kind of problem before computers were available, mathematicians have studied it extensively. For a small class of functions, it is indeed possible to determine the area exactly. For the other cases, mathematicians have developed several methods to determine close estimates. Since these methods involve lots of mechanical calculations, they are natural candidates for computer functions.


 

external

Figure: Integrating a function f between a and b


A general integration function must consume three inputs: a, b, and the function f. The fourth part, the x axis, is implied. This suggests the following contract:

;; integrate : (number -> number) number number -> number
;; to compute the area under the graph of f between a and b 
(define (integrate f a b) ...) 

Kepler suggested one simple integration method. It consists of three steps:

  1. divide the interval into two parts: tex2html_wrap_inline72527 and tex2html_wrap_inline72529 ;
  2. compute the area of each trapezoid; and
  3. add the two areas to get an estimate at the integral.


Exercises

Exercise 23.4.1

Develop the function integrate-kepler. It computes the area under some the graph of some function f between left and right using Kepler's rule. Solution


Another simple method is to think of the area as a sequence of many small rectangles. Each rectangle is as tall as the function graph in, say, the middle of the rectangle. Figure [cross-reference] shows two examples. By adding up the area of the rectangles, we get a good estimate at the area under the graph. The more rectangles we consider, the closer the estimate is to the actual area.

Let us agree that R stands for the number of rectangles that we wish to consider. To determine how large these rectangles are, we need to figure out how large their sides are. The length of the side on the x axis is the length of the interval divided by the number of rectangles:

displaymath72533

For the height of the rectangle, we need to determine its midpoint and then the value of f at the midpoint. The first midpoint is clearly at a plus half of the width of the rectangle, that is, if

displaymath72539

the area is

displaymath72541

where W stands for width and S for step from now on.

To get from the rectangle starting at a to the next one on the right, we must add the width of one rectangle. That is, the next midpoint (called tex2html_wrap_inline72547 in figure [cross-reference]) is at

displaymath72549

the third one at

displaymath72551

and so on. The following table explains the three sequences that are involved in the usual manner:

displaymath72553

In the second row, M stands for midpoint. The first rectangle has index 0, the last one R - 1.

Using this sequence of rectangles, we can now determine the area under the graph as a series:

displaymath72559


Exercises Exercise 23.4.2

Develop the function integrate. It computes the area under some the graph of some function f between left and right using the rectangle-series method.

Use test cases for f, a, and b for which one can determine the area exactly and easily by hand, for example, (define (id x) x). Compare the results with those of integrate from exercise [cross-reference].

Make R a top-level constant:

;; R : number of rectangles to approximate integral
(define R ...) 
Test integrate on sin and increase R gradually from 10 to 10000. What happens to the result? Solution


[previous] [up] [next]     [index]
Next: The Slope of a Up: Mathematical Examples Previous: Taylor Series

PLT