For simplicity and reasonably good accuracy one can use Simpson's rule for adaptive quadrature. In this case we have
and the error formula is valid for p=4. The criterion for acceptance is
An approach similar to the one described above using Simpson's rule is implemented by MATLAB in the file quad.m.. There is a higher precision formula called quad8.m in MATLAB.
For purposes of illustration consider the integral
The integrand is rapidly varying for
as is seen in
the following graph:
To see how the grid evolves you can download the movie, si_movie.mpg. The final grid chosen, using our program adpsim.m, is depicted in the following graph where the vertical lines indicate the grid
(using
):
where the computed value is 0.513013 and required 137 function evaluations.
The same integral was used with quad.m and gave the computed value of 0.5130
with 681 function evaluations. Also, MATLAB gave the message: recursion
level limit reached, singularity likely. If you would like a zipped copy of the MATLAB program adpsim.m, click
here adpsim.zip .
Another interesting integral involves the so-called humps function that comes with MATLAB. A graph of this function is given below:

The movie humps.mpg shows the evolution of the grid when the program adpsim.m is used with the absolute error tolerance specified as .00001. To view this movie on a PC running Windows 3.x with Netscape you should install the helper application Vmpeg 1.7 and configure the viewer to play at 2 frames per second.
It is instructive to apply the MATLAB program quad.m to the problem with
:
and explain the resulting computed value.