-
Convergence of Newton–Cotes rules
Use the composite trapezoidal and Simpson rules for the three
smooth test integrals below. Start with a small number of
subintervals and repeatedly double it. Plot the absolute error
versus the number of subintervals and see whether the expected
convergence rate appears in your results.
∫0π sin(x) dx = 2
∫01 ex dx = e − 1
∫01 dx/(1 + x2) = π/4
For a more challenging case, try
∫01 √x dx = 2/3.
The integrand is continuous but has an infinite derivative at
x = 0. Estimate the observed convergence rate from the slope of
the error curve. How does it differ from the nominal rates for
smooth integrands?
-
Simpson versus Gauss–Legendre quadrature
Compare composite Simpson and Gauss–Legendre quadrature on
the integrals below. Give the two methods roughly comparable
numbers of function evaluations and compare the resulting errors.
∫01 ex dx = e − 1
∫01 dx/(1 + x2) = π/4
∫01 e−x2 dx = (√π/2) erf(1)
Which method gains accuracy more quickly for these smooth
functions? Is the answer the same for all three integrals? As
a hint, the complex singularities of 1/(1+x²) at
x = ±i are relatively close to the real
integration interval and can slow high-order convergence.
-
Two peaks on very different scales
Consider a function with one broad peak and one much narrower
feature,
f(x) = e−40(x − 0.30)2
+ 0.05e−4000(x − 0.72)2,
0 ≤ x ≤ 1.
Compare composite Simpson on a uniform grid with adaptive
Simpson or adaptive Gauss–Kronrod integration. Use several
grid sizes or tolerances and plot the integrand together with
the points or subintervals used by each method.
Can a uniform-grid calculation appear nearly converged while
still missing part of the narrow peak? What changes if the
narrow peak is made even narrower? For the parameters above,
the narrow peak contributes only about 0.5% of the total
integral, so a calculation can look convincing while still
missing it.
-
Requested tolerance versus actual error
Run an adaptive integration routine with requested tolerances
from about 10−3 down to
10−12. Use the two integrals
∫01 ex dx = e − 1
∫01 e−20x dx
= (1 − e−20)/20.
For each tolerance, record the numerical result, the routine's
error estimate, the actual error, and the number of function
evaluations if it is available. Does asking for a tolerance of
10−10 actually produce an error close to
10−10?
-
An endpoint singularity that can be removed
Evaluate
∫01 ln(1 + x)/√x dx
= π + 2 ln(2) − 4.
First apply an adaptive routine directly. Then use the
substitution x = t2 and integrate the transformed
function on 0 ≤ t ≤ 1. Compare accuracy and computational
effort.
Plot both integrands. Why is the transformed problem easier
numerically even though the value of the integral is unchanged?
The square-root behavior here is closely related to the
turning-point behavior in the WKB project below.
-
Two transformations for an infinite interval
Evaluate
∫0∞ e−x sin(x) dx = 1/2
by mapping the semi-infinite interval onto a finite interval in
two different ways:
x = t/(1 − t), 0 ≤ t < 1
x = tan(πt/2), 0 ≤ t < 1.
Plot the transformed integrands and compare convergence,
function-evaluation counts, and sensitivity near t = 1.
Which transformation works better for this particular integral?
Explain the result by examining how rapidly each transformed
integrand approaches zero or oscillates as t → 1.
-
Cauchy principal value
Consider
PV ∫−11 cos(x)/(x − 0.2) dx.
First remove a symmetric interval
(0.2 − δ, 0.2 + δ) around the pole and study
the result as δ becomes smaller. Then evaluate the same
integral using analytical subtraction or a library routine
designed for principal values.
The reference value is approximately
−0.5912784964342435, matching the principal-value
benchmark on the Chapter 7 resources page.
For additional practice, repeat the calculation for
PV ∫−11 ex/(x − 0.3) dx.
Its reference value is approximately
1.620314024361904.
Why is it unsafe simply to give an ordinary quadrature routine
an interval containing the pole?
-
What happens as the oscillation frequency grows?
Study
I(ω) = ∫01 e−x cos(ωx) dx
I(ω) = [1 + e−1
(ω sinω − cosω)]/(1 + ω2).
for ω = 10, 25, 50, 100, and larger values. Compare
composite Simpson with an oscillatory-specific method such as
Filon quadrature or a weighted library routine.
Track both the error and the number of function evaluations.
How quickly does a general-purpose method become expensive as
the oscillations get faster? The case ω = 50
is also used as a benchmark on the
Chapter 7 resources page.
-
Cancellation inside the integrand
Evaluate
I(δ) = ∫01
[e−x − e−(1+δ)x] dx,
δ = 10−8.
A high-precision reference value is
I(δ) ≈ 2.642411168541014 × 10−9.
Compare direct evaluation of the integrand with the stable form
−e−xexpm1(−δx).
Also derive the leading-order approximation
I(δ) ≈ δ(1 − 2/e). Use
increased-precision arithmetic to evaluate the reference, since
subtracting the two separately integrated exponentials in
ordinary double precision suffers from the same cancellation as
the direct integrand.
This exercise is less about the quadrature formula itself and
more about an important lesson: an integration routine cannot
recover accuracy that has already been lost while evaluating
the integrand.
-
Two-dimensional product quadrature
Apply an n × n Gauss–Legendre product rule to
∫01
∫01
dy dx /(1 + x2 + y2).
Use several values of n and plot the absolute error against the
total number n2 of function evaluations. Compare your
result with a two-dimensional library routine if one is
available. A high-accuracy reference value is
0.6395103518703110.
Notice how quickly the number of points grows when a
one-dimensional rule is extended by taking products.
-
How accurate should the inner integral be?
Use the variable-boundary integral
∫01
∫0sin(x)
x2/(y2 + 2) dy dx.
Hold the outer tolerance fixed while changing the tolerance used
for the inner integration. Find the point at which making the
inner calculation more accurate no longer improves the final
answer, and then make the inner tolerance looser until it begins
to affect the result noticeably.
The goal is to see that nested integration has two accuracy
controls that must work together rather than independently.
-
Companion implementation versus a library routine
Choose one of the Chapter 7 companion programs and compare it
with a widely used routine in your preferred language:
MATLAB integral or quadgk,
Python/SciPy quad, C++/GSL, or
Fortran/QUADPACK.
Test both routines on at least one easy integral and one more
demanding case from the exercises above. Compare accuracy,
error estimates, function-evaluation counts when available, and
ease of use.
Which implementation helps you understand the algorithm better?
Which would you choose for a larger scientific calculation, and
why?