Foundations to Frontier
Tests
A. Mathematical Foundations › A8 Numerical Methods and Scientific Computing

Numerical Integration: Quadrature and Monte Carlo

Most integrals in science and engineering cannot be done in closed form: expected costs, probabilities of collision, orbital averages, posterior expectations. This topic builds the toolkit: trapezoid and Simpson rules with their O(h²) and O(h⁴) errors, Gauss–Legendre quadrature that is exact for polynomials of degree 2n − 1, the surprising spectral accuracy of the trapezoid rule for periodic functions, and Monte Carlo with its dimension-free 1/√N rate. You will measure every rate, beat the curse of dimensionality with Monte Carlo and quasi-Monte Carlo, and use importance sampling to estimate a 3×10⁻⁵ collision-type tail probability to 1% accuracy.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Measuring an area with strips and darts

To find the area of a lake on a map, you can cover it with thin strips and add up their areas, or throw darts at the map and count what fraction land in the water. Strips work brilliantly on a flat map. In very many dimensions, there are far too many strips to count, but darts still work. These are the two big ideas of numerical integration: quadrature (clever strips) and Monte Carlo (random darts).

Adding up areas: how fast does each rule converge?
1e-41e-81e-121e-16n (log) →
Gauss with n = 5: estimate 1.71828182846 vs exact 1.71828182846 · error 6.54e-13
Trapezoid error falls like 1/n², Simpson like 1/n⁴, and Gauss–Legendre (nodes at Legendre roots, exact for polynomials up to degree 2n − 1) geometrically for smooth integrands. A kink (√x) or a nearby complex pole (the Runge function) slows every rule down. Monte Carlo converges like 1/√n in any dimension: terrible in 1-D, but the only rule whose rate doesn't degrade with dimension.
Why engineers care

Conjunction assessment for satellites integrates a Gaussian over a collision disc to get a probability of collision. Uncertainty quantification for entry, descent and landing averages over thousands of dispersed trajectories. Bayesian estimation integrates over posteriors. Choosing the right integration method decides whether the answer takes a millisecond or a week.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Monte Carlo integration uses…
  2. 2. In very high dimensions, which approach still works?
  3. 3. Using more, thinner strips usually makes the area estimate…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Newton–Cotes rules

With nn panels of width h=(b−a)/nh = (b - a)/n:

  • Trapezoid: Tn=h[12f0+f1+⋯+fn−1+12fn]T_n = h\big[\tfrac12f_0 + f_1 + \dots + f_{n-1} + \tfrac12f_n\big], error −(b−a)h212f′′(ξ)-\frac{(b - a)h^2}{12}f''(\xi).
  • Simpson (even nn): Sn=h3[f0+4f1+2f2+⋯+4fn−1+fn]S_n = \frac h3\big[f_0 + 4f_1 + 2f_2 + \dots + 4f_{n-1} + f_n\big], error −(b−a)h4180f(4)(ξ)-\frac{(b - a)h^4}{180}f^{(4)}(\xi).

Halving hh cuts the trapezoid error by 4 and the Simpson error by 16.

Monte Carlo

With xi∼U[a,b]dx_i\sim\mathcal U[a, b]^d: ∫f≈∣Ω∣N∑f(xi)\int f\approx\frac{\lvert\Omega\rvert}N\sum f(x_i). The standard error is σf/N\sigma_f/\sqrt N in any dimension. Always report it.

📝 Quick check (Level 1)
0/3 answered
  1. 1. Halving h reduces Simpson's error by about…
  2. 2. Monte Carlo error falls like…
  3. 3. The trapezoid rule is exact for…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Gaussian quadrature

Choose both nodes and weights. With nn nodes at the roots of the Legendre polynomial PnP_n, the rule is exact for polynomials of degree 2n−12n - 1. For analytic integrands the error falls geometrically. Variants: Gauss–Hermite for e−x2e^{-x^2} weights (Gaussian expectations, the unscented transform’s cousin), Gauss–Laguerre and Gauss–Kronrod (adaptive error estimates, as in QUADPACK and scipy.integrate.quad).

Periodic functions

For a smooth periodic integrand over a full period, the plain trapezoid rule converges exponentially (Trefethen and Weideman, 2014). 16 points give ∫02πecos⁡xdx\int_0^{2\pi}e^{\cos x}dx to machine precision.

Dimension and variance reduction

A tensor-product rule with mm points per axis needs mdm^d points: the curse of dimensionality. Ways around it:

  • Monte Carlo: O(N−1/2)O(N^{-1/2}), dimension-free.
  • Quasi-Monte Carlo (Halton, Sobol): O((log⁡N)d/N)O((\log N)^d/N) for smooth integrands.
  • Importance sampling: sample from qq and weight by p/qp/q to concentrate samples where the integrand matters.
  • Control variates, antithetic and stratified sampling.
🐍 Exercise 1: quadrature rules and their rates
Implement the trapezoid, Simpson and Gauss–Legendre rules. Measure the O(h²) and O(h⁴) rates and the geometric Gauss convergence, verify degree-(2n − 1) exactness, and show the spectral accuracy of the trapezoid rule on a periodic integrand.
📝 Quick check (Level 2)
0/3 answered
  1. 1. n-point Gauss–Legendre is exact up to degree…
  2. 2. Tensor rules in d dimensions with m points per axis need…
  3. 3. For a smooth periodic function over a full period, the trapezoid rule converges…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Trapezoid error

On one panel [0,h][0, h], the linear interpolant pp has error f−p=12f′′(ξx)x(x−h)f - p = \frac12f''(\xi_x)x(x - h). Integrate: ∫0hx(x−h) dx=−h3/6\int_0^hx(x - h)\,dx = -h^3/6, giving −h312f′′(ξ)-\frac{h^3}{12}f''(\xi) per panel. Summing n=(b−a)/hn = (b - a)/h panels gives −(b−a)h212f′′(ξ)-\frac{(b - a)h^2}{12}f''(\xi). ∎

Gauss exactness

Divide a degree-2n−12n - 1 polynomial by PnP_n: p=qPn+rp = qP_n + r with deg⁡q,deg⁡r≤n−1\deg q, \deg r\le n - 1. Orthogonality gives ∫qPn=0\int qP_n = 0. At the nodes Pn(xi)=0P_n(x_i) = 0, so the rule sees only rr, which it integrates exactly (being interpolatory on nn nodes). ∎

Importance sampling

Ep[g]=Eq[g p/q]\mathbb E_p[g] = \mathbb E_q[g\,p/q]. The variance is minimized by q∗∝∣g∣pq^*\propto\lvert g\rvert p. For a Gaussian tail P(X>c)P(X > c), shifting the sampler to N(c,1)\mathcal N(c, 1) gives weight e−cx+c2/2e^{-cx + c^2/2} and relative error O(1/N)O(1/\sqrt N) independent of how rare the event is (Owen, 2013).

Exercise 3.1: trapezoid for x² on [0, 1] with n = 2

h=12h = \frac12: 12(0+2⋅14+1)/2=0.375\frac12(0 + 2\cdot\frac14 + 1)/2 = 0.375. The error 0.0417 matches 1⋅(1/4)12⋅2=1/24\frac{1\cdot(1/4)}{12}\cdot2 = 1/24.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The trapezoid error per panel is…
  2. 2. Gauss exactness relies on…
  3. 3. The optimal importance density is proportional to…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Dimensions and rare events

With a fixed budget of 4096 function evaluations, a tensor Gauss rule is exact to rounding in 2-D (64 points per axis). In 12-D only 2 points per axis remain and its error is 15%, while Monte Carlo stays near 3%. The second half of the exercise is a collision-type tail probability P(X>4)=3.2×10−5P(X > 4) = 3.2\times10^{-5}. Plain Monte Carlo with 20 000 samples sees about one hit, so its relative error is about 100%. Importance sampling centred on the threshold gets about 1%. This is the logic behind sampling-based conjunction screening and EDL Monte Carlo dispersion analyses.

🐍 Exercise 2 (research): curse of dimensionality and rare events
Compare tensor Gauss, Halton quasi-Monte Carlo and Monte Carlo on the same 4096-point budget in 2, 6 and 12 dimensions. Then estimate a Gaussian tail probability with naive and importance-sampled Monte Carlo.

Integration in AI, robotics and aerospace

  • Space situational awareness: probability of collision as a 2-D integral over the encounter plane (Foster and Estes, 1992; Alfano, 2005). Monte Carlo is used for non-Gaussian cases.
  • Entry, descent and landing: Monte Carlo dispersion campaigns with thousands of 6-DoF simulations, used to verify landing-ellipse requirements.
  • State estimation: the unscented transform and Gauss–Hermite filters use deterministic quadrature nodes; particle filters use Monte Carlo.
  • Machine learning: stochastic gradients are Monte Carlo integrals; QMC is used in Bayesian optimization and rendering.

References

  1. P. Davis, P. Rabinowitz (1984). Methods of Numerical Integration, 2nd ed. Academic Press.
  2. L. N. Trefethen, J. A. C. Weideman (2014). “The exponentially convergent trapezoidal rule.” SIAM Review, 56(3).
  3. L. N. Trefethen (2008). “Is Gauss quadrature better than Clenshaw–Curtis?” SIAM Review, 50(1).
  4. A. Owen (2013). Monte Carlo Theory, Methods and Examples. statweb.stanford.edu/~owen/mc.
  5. H. Niederreiter (1992). Random Number Generation and Quasi-Monte Carlo Methods. SIAM.
  6. J. Foster, H. Estes (1992). “A parametric analysis of orbital debris collision probability and maneuver rate for space vehicles.” NASA JSC-25898.
  7. S. Alfano (2005). “A numerical implementation of spherical object collision probability.” Journal of the Astronautical Sciences, 53(1).
  8. R. Piessens et al. (1983). QUADPACK: A Subroutine Package for Automatic Integration. Springer.