To illustrate the ideas of Section 2.3, the second column of
Table 1 displays the result of the trapezoid rule
(13) for the integral
as a function of the number of intervals
.
Table:
Results of trapezoid and Simpson's integration of
for
intervals
| |
|
Trapezoid |
Trapezoid |
Richardson Extrap |
Simpson |
| N |
h |
( ) |
(w/ bug) |
(
) |
( ) |
| 10 |
0.1000 |
1.000900562871 |
1.036067656056 |
1.000000280034 |
1.000000280034 |
| 100 |
0.0100 |
1.000009016731 |
1.003606737630 |
1.000000000028 |
1.000000000028 |
| 1000 |
0.0010 |
1.000000090168 |
1.000360673760 |
1.000000000000 |
1.000000000000 |
| 10000 |
0.0001 |
1.000000000901 |
1.000036067376 |
1.000000000000 |
1.000000000000 |
|
Displayed in this way the data for the trapezoid rule exhibit an
interesting pattern: each increase in the number of intervals
by a
factor of ten shifts the pattern of digits (``901'') representing the
error two places to the right. This is the visual representation of
our mathematical analysis: the shifting to the right by two places
corresponds precisely to quadratic scaling of the error with
and
the pattern of shifting digits represents precisely the prefactor on
in (16),
Displaying the results of a numerical calculation in this way is a
very powerful tool for detecting bugs and correcting errors. The
convergence of the trapezoid rule is quite delicate and even
small programming errors will destroy it. The third column of the
table, for instance, shows the typical behavior when the factor of 1/2
is forgotten at the end points and/or when dividing by
instead of
. A routine with either bug indeed converges to the correct
result, but the convergence is only linear in
and such subtle bugs
are easily detected.
Tomas Arias
2004-01-26