Chapter 7

Looping in Maple

7.8 Area as a Function

The area under the curve is an implicit function of the end points of the integral. This can easily be illustrated by looking at the area under the Skewed Mexican Hat function as a function of the upper limit of the interval. This can be done on the numerical grid by storing the area as we add the area of each new strip to the total area. This is done from within the "for" loop which scans over the grid; each stored value corresponds to the area under the curve up to that particular grid point.

Maple allows us to compute the area exactly via the "int" command. The results can be stored in an array. The exact answer is obtained by specifying the interval for the "int" command to be {xmin,xi} to correspond to the integral from x_min to the grid point xi.

The following Maple worksheet implements these ideas. The array area_t[k] stores the area obtained via the trapezoidal rule and area_e[k] stores the exact answer. These values are plotted simultaneously in point style. The area function is plotted at half interval in x to make it evident that the trapezoidal rule approximates a function on a strip level.

The differences between the value of the exact integral and the value of the integral done via the trapezoidal rule represent the error in the trapezoidal rule result. The trend of the integral function is certainly well reproduced. The error is relatively small even with this quite coarse grid (21 points). The error in general accumulates with distance of integration; yet the error in each strip can be positive or negative (over estimate or under estimate of the real area) which leads to an error which is not uniform with distance.

Maple can perform this integral analytically; consequently the "area" function can be made a Maple function, or a map, via the "unapply" command. The Maple statement

      unapply( int(f(x),x=x_min..X), X );

first does the integral via the "int" statement from x_min to X which brings back an expression containing X; second it transforms the expression into a Maple Map (Maple function) via "unapply".

The generated plot is shown below.


 
Section 7.7 Chapter 7 Exercises       TOC

Any questions or suggestions should be directed to
Michel Vallières at vallieres@physics.drexel.edu