Quadrature and adaptive integration
Approximate integrals with explicit rules, refinement estimates, and a clear distinction between an estimated and guaranteed error.
On this page
The question for today
What you’ll understand
- Interpret quadrature as integrating a local approximation.
- Compute a refinement-based Simpson error estimate.
- Explain why adaptive sampling can miss unresolved features.
An integral combines contributions across a whole domain, but numerical quadrature can inspect only finitely many points. The challenge is to spend those evaluations where they reveal the answer, while tracking what remains unseen. A quadrature rule converts sampled values into a weighted sum. An adaptive algorithm adds a decision about where to sample next. Both rely on assumptions about smoothness and scale. This lesson derives useful rules, follows a refinement calculation exactly, and asks what a returned tolerance actually certifies when the integrand contains a narrow peak or an oscillation.
Integrate an approximation you understand
The trapezoid rule replaces a function by a straight line across a panel and integrates that line. Simpson's rule instead integrates the quadratic interpolant through the endpoints and midpoint. Both are exact for certain low-degree polynomials, but exactness on a test class is not exactness for arbitrary functions. Composite rules divide the interval into panels and add their contributions. Panel widths, endpoint weights, and evaluation reuse must be handled consistently when comparing different resolutions.
For a sufficiently smooth function on a finite interval, the composite trapezoid error usually decreases quadratically with uniform step size, while composite Simpson error decreases to fourth order. Derivative bounds can turn these statements into rigorous estimates, but samples alone generally do not supply those bounds. Endpoint singularities, discontinuities, and rapidly changing derivatives can spoil the anticipated rate. Splitting at a known discontinuity or changing variables near a singular endpoint may be more effective than blindly applying a higher-order smooth formula.
Use disagreement to decide where to refine
Compute a coarse Simpson approximation on a panel and a refined approximation from its two halves. If the leading fourth-order asymptotic error dominates, halving the mesh reduces that error by about sixteen. Their difference therefore estimates fifteen times the refined error, up to sign. This supplies a practical local error indicator without knowing the exact integral. Reusing shared values keeps the comparison economical, since only the new quarter points require fresh function evaluations.
An adaptive strategy subdivides panels whose estimated errors are too large and combines the accepted contributions. A global absolute-error budget must be distributed across subpanels or controlled by summing their indicators; allowing every subpanel the full budget would not prove the requested global tolerance. Relative tolerances also need an absolute floor when the final integral nearly cancels. Maximum evaluation counts and minimum panel sizes provide honest failure modes when the requested target cannot be resolved.
A tolerance request is not universal proof
Two rules can agree because both missed the same narrow peak. No finite set of unconstrained samples can rule out an arbitrarily large smooth bump hidden between them. Oscillatory cancellation creates another risk: many positive and negative contributions may leave a small total, making relative accuracy difficult even when local values are well resolved. If the function's structure is known, use that information through interval splitting, specialized oscillatory rules, analytic subtraction, or a transformation that exposes the relevant scale.
Validate with independent formulations when possible. Compare a changed variable, a different quadrature family, or a known limiting case, rather than merely tightening the same algorithm's tolerance. Distinguish the quadrature error from errors in the integrand itself, such as an inner nonlinear solve. Integrating an inaccurate function more carefully does not recover the intended integral. A useful result records the value, estimated error, evaluation count, assumptions, and whether the algorithm exhausted its budget. That is enough information to decide the next computation intelligently.
Work it through
Refine Simpson's rule on a quartic
Approximate the integral of x⁴ on [0,1] with one Simpson panel and then two equal panels. Compare the error estimate with the exact integral 1/5.
The coarse panel is [0+4(1/16)+1]/6=5/24≈0.2083333333. It is not exact, because the quartic exceeds Simpson's cubic exactness class.
The refined composite rule has spacing h=1/4 and samples 0,1/256,1/16,81/256,1. Its weighted sum is (1/12)[1+4(82/256)+2(1/16)]=77/384≈0.2005208333.
The signed correction is (77/384−5/24)/15=(−3/384)/15=−1/1920≈−0.0005208333. Adding it to the refined value gives exactly 0.2 in exact arithmetic.
Here the refined error is exactly +1/1920, so the indicator has the correct magnitude. This perfect correction is special to the quartic's single relevant error term; it is not a universal guarantee for every smooth integrand.
Refinement makes the error observable through a justified asymptotic model. The known integral independently checks the indicator and its sign.
The living notebook
Explore the model
Interactive lab · function
Area as a target for numerical approximation
Set a=1 and move x from zero to one on y=a x². The lab reports the exact-form signed area a x³/3 from zero to x; at one it is 1/3. Predict why Simpson's rule is exact for this quadratic, then change a. The lab does not run quadrature, display panels, or adapt a mesh, and the quartic example is not plotted.
- y at chosen x
- 0.608
- Tangent slope · 2ax
- 1.35
- Signed area · ax³/3
- 0.182
This lab uses only y = ax². Playback traces the curve within the fixed integration interval from 0 to x; it does not estimate numerical error or change the chosen point. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forUse an analytically known area to validate an integration routine before trusting its error estimate on unfamiliar data.
Pause & reason
Check your understanding
Your turn
Try it yourself
Apply one Simpson panel to x³ on [0,2]. Compute the exact integral separately.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The midpoint is one and the interval length is two.
Compare with the solution
Simpson gives (2/6)[0+4(1)+8]=4. The antiderivative x⁴/4 gives 16/4=4. Agreement follows from cubic exactness in exact arithmetic; it does not require a small interval or an asymptotic limit.
Keep the idea
Take it with you
- Quadrature rules integrate specific local approximations.
- Adaptive indicators rely on an error model and require global budget accounting.
- Independent structure and validation are essential when sampling may miss important features.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.