5.3 Integration algorithms
Source: Ideas from Computational Physics (Landau, Páez, Bordeianu), §5.3–§5.3.5. Rewritten in original wording. Continues 5.2 Extrapolated difference. Labs: 5.3b Integration labs.
Problem: integrate a spectrum
A counter records a rate — particles per unit time. The number that arrived in the first second is the area under that rate curve:
You may have no antiderivative in closed form — only samples of the rate. The job is numerical quadrature: turn the integral into a finite, stable sum.
Box counting (Riemann sums)
Graph-paper counting of boxes under a curve is the oldest numerical integration picture; the name quadrature stuck even for rules far past plain boxes. On a computer there is no infinitesimal — every practical rule is a weighted sum of samples. Walk the skeleton, left boxes, and midpoint rule — pick each equation among lookalikes.
Figure 5.2 shows the idea: four equal panels of width , five marked abscissae from to . The shaded rectangles are one concrete choice of heights (here left-endpoint samples).
Equal-spacing workhorses: trapezoid and Simpson
Partition into panels of width and write . Walk the one-panel trapezoid, composite trapezoid, and composite Simpson — pick the matching equation at each step.
Simple integration error estimates
Choose a rule that reaches a useful answer with the fewest samples. A crude estimate of the algorithmic error for equal-spacing rules expands in a Taylor series about a panel midpoint, then multiplies by the number of panels to cover . Relative error is when the integral is not tiny.
Standard leading results for smooth :
Those scalings are illuminating:
- Simpson needs fewer points and has less error than trapezoid for the same smooth .
- With Simpson (and other higher-order rules) you can push error near machine precision.
- The best numerical integral is not . A modest often sits near the sweet spot; larger mostly buys round-off.
Higher-order algorithms (Romberg)
As with differentiation, if you know how the error depends on , you can cancel the leading term. Walk the trap/Simpson scalings, the / expansions, the Romberg combo, and the audit — pick the matching equation at each step.
Elementary weights and a sanity check
Equal-interval “single-block” rules use a small stencil that you tile across . Shared endpoints of adjacent blocks are counted twice when blocks are strung together. Typical elementary weights:
| Rule | Panels / block | Weights (factor omitted) |
|---|---|---|
| Trapezoid | 1 | |
| Simpson | 2 | |
| Three-eighths | 3 | |
| Milne (Boole) | 4 |
If your weight list fails (the guide’s last step), the stencil is wrong before you ever touch a nontrivial .
Quadrature, errors, Romberg
1 / 4N(1)=∫₀¹ (dN/dt) dt asks you to…
Pick an answer to see if you are right.
Next: 5.3b Integration labs. Then 5.4 Gaussian quadrature.