Mathematics 371 -- Numerical Analysis

Adaptive Quadrature

November 7, 2001

An example: f( x ) = 100*x^2*exp(-4*x)*sin(10/x) . This is a good candidate for adaptive

quadrature over an interval like [1,3] since the graph of the function is slowly varying

over portions of the interval and rapidly varying over others:

> f:=x->100*x^2*exp(-4*x)*sin(10/x);

f := proc (x) options operator, arrow; 100*x^2*exp(...

> plot(f(x),x=1..3);

[Maple Plot]

>

Here is a listing of the Maple code for Adaptive Quadrature

> interface(verboseproc=2):

> read `/home/fac/little/public_html/Num01/Adapt.map`;

> print(Adapt);

proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...
proc (f, a, b, tol, verbose) local h, c, m, d, fa, ...

Using adaptive quadrature:

> count := 0;

count := 0

> approx1:=Adapt(f,1.0,3.0,.00005,true);

"starting integration on [", 1.0, 3.0, "]"

"starting integration on [", 1.0, 2.000000000, "]"

"starting integration on [", 1.0, 1.500000000, "]"

"starting integration on [", 1.0, 1.250000000, "]"

"starting integration on [", 1.0, 1.125000000, "]"

"starting integration on [", 1.0, 1.062500000, "]"

"tolerance met"

"starting integration on [", 1.062500000, 1.125000000, "]"

"tolerance met"

"starting integration on [", 1.125000000, 1.250000000, "]"

"tolerance met"

"starting integration on [", 1.250000000, 1.500000000, "]"

"starting integration on [", 1.250000000, 1.375000000, "]"

"tolerance met"

"starting integration on [", 1.375000000, 1.500000000, "]"

"tolerance met"

"starting integration on [", 1.500000000, 2.000000000, "]"

"starting integration on [", 1.500000000, 1.750000000, "]"

"tolerance met"

"starting integration on [", 1.750000000, 2.000000000, "]"

"tolerance met"

"starting integration on [", 2.000000000, 3.0, "]"

"starting integration on [", 2.000000000, 2.500000000, "]"

"tolerance met"

"starting integration on [", 2.500000000, 3.0, "]"

"tolerance met"

approx1 := .1978428881

Maple's computed value:

> exact:=evalf(Int(f(x),x=1..3));

exact := .1978408265

> err:=abs(exact1-approx1);

err := .20616e-5

The number of times the Adapt procedure was called recursively:

> count;

17

CAUTION: It is not the case that the error from the adaptive

quadrature procedure will always be less than or equal to the

error tolerance value (even ignoring round-off error phenomena).

(The derivation of the error estimate uses the assumption that two

values of the fourth derivative of f are equal, which may be far

from true.) For example:

> approx:=Adapt(f,1.0,3.0,.0001,false);

approx := .2006487037

> abs(approx-exact);

.28078772e-2

Note that the actual error is larger than the error tolerance in this case.