Consider the function graph in figure~#figfuncint#31567>. Suppose we wish
to know the area between the <#31568#>x<#31568#>-axis, the fat lines labeled <#31569#>a<#31569#> and <#31570#>b<#31570#>, and the graph. Determining the area under the graph of
a function for some specific interval is called <#31571#>integrating a function<#31571#>. 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.
\ \ \ <#65924#> <#65924#>
<#65925#>Figure: Integrating a function <#31573#>f<#31573#> between <#31574#>a<#31574#> and <#31575#>b<#31575#><#65925#>
A general integration function must consume three inputs: <#65926#><#31577#>a<#31577#><#65926#>,
<#65927#><#31578#>b<#31578#><#65927#>, and the function <#65928#><#31579#>f<#31579#><#65928#>. The fourth part, the <#31580#>x<#31580#>-axis, is implied. This suggests the following contract:
<#71430#>;; <#65929#><#31585#>integrate<#31585#> <#31586#>:<#31586#> <#31587#>(number<#31587#> <#31588#><#31588#><#31589#>-;SPMgt;<#31589#><#31590#><#31590#> <#31591#>number)<#31591#> <#31592#>number<#31592#> <#31593#>number<#31593#> <#31594#><#31594#><#31595#>-;SPMgt;<#31595#><#31596#><#31596#> <#31597#>number<#31597#><#65929#><#71430#>
<#71431#>;; to compute the area under the graph of <#65930#><#31598#>f<#31598#><#65930#> between <#65931#><#31599#>a<#31599#><#65931#> and <#65932#><#31600#>b<#31600#><#65932#><#71431#>
<#31601#>(define<#31601#> <#31602#>(integrate<#31602#> <#31603#>f<#31603#> <#31604#>a<#31604#> <#31605#>b)<#31605#> <#31606#>...)<#31606#>
Kepler suggested one simple integration method. It consists of three steps:
- divide the interval into two parts:
#tex2html_wrap_inline73404# and #tex2html_wrap_inline73406#;
- compute the area of each <#31613#>trapezoid<#31613#>; and
- add the two areas to get an estimate at the integral.
<#31617#>Exercise 23.4.1<#31617#>
Develop the function <#65933#><#31619#>integrate-kepler<#31619#><#65933#>. It coomputes the area under
some the graph of some function <#65934#><#31620#>f<#31620#><#65934#> between <#65935#><#31621#>left<#31621#><#65935#> and
<#65936#><#31622#>right<#31622#><#65936#> using Kepler's rule.~ Solution<#65937#><#65937#>
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~#figfuncint#31630> 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 <#65938#><#31631#>R<#31631#><#65938#> 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 <#31632#>x<#31632#>-axis is the length of the interval divided by the number of
rectangles:
#displaymath73408#
For the height of the rectangle, we need to determine its midpoint and then
the value of <#31635#>f<#31635#> at the midpoint. The first midpoint is clearly at
a plus half of the width of the rectangle, <#31636#>i.e.<#31636#>, if
#displaymath73412#
the area is
#displaymath73414#
where <#31639#>W<#31639#> stands for <#31640#>width<#31640#> and <#31641#>S<#31641#> for <#31642#>step<#31642#>
from now on.
To get from the rectangle starting at <#65942#><#31643#>a<#31643#><#65942#> to the next one on the
right, we must add the width of one rectangle. That is, the next midpoint
(called #tex2html_wrap_inline73416# in figure~#figfuncint#31644>) is at
#displaymath73418#
the third one at
#displaymath73420#
and so on.
The following table explains the three sequences that are involved in the
usual manner:
#displaymath73422#
In the second row, <#31652#>M<#31652#> 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:
#displaymath73426#
<#31658#>Exercise 23.4.2<#31658#>
Develop the function <#65944#><#31660#>integrate<#31660#><#65944#>. It coomputes the area under
some the graph of some function <#65945#><#31661#>f<#31661#><#65945#> between <#65946#><#31662#>left<#31662#><#65946#> and
<#65947#><#31663#>right<#31663#><#65947#> using the rectangle-series method.
Use test cases for <#65948#><#31664#>f<#31664#><#65948#>, <#65949#><#31665#>a<#31665#><#65949#>, and <#65950#><#31666#>b<#31666#><#65950#> for which one can
determine the area exactly and easily by hand, <#31667#>e.g.<#31667#>, <#65951#><#31668#>(define<#31668#>\ <#31669#>(id<#31669#>\ <#31670#>x)<#31670#><#31671#> <#31671#><#31672#>x)<#31672#><#65951#>. Compare the results with those of <#65952#><#31673#>integrate<#31673#><#65952#> from
exercise~#exintegralkepler#31674>.
Make <#65953#><#31675#>R<#31675#><#65953#> a top-level constant:
<#71432#>;; <#65954#><#31680#>R<#31680#><#65954#> : number of rectangles to approximate integral<#71432#>
<#31681#>(define<#31681#> <#31682#>R<#31682#> <#31683#>...)<#31683#>
Test <#65955#><#31687#>integrate<#31687#><#65955#> on <#65956#><#31688#>sin<#31688#><#65956#> and increase <#65957#><#31689#>R<#31689#><#65957#>
gradually from <#65958#><#31690#>10<#31690#><#65958#> to <#65959#><#31691#>10000<#31691#><#65959#>. What happens to the
result?~ Solution<#65960#><#65960#>