∫Numerical Differentiation and Integration
Monte Carlo Integration
Expectations as integrals, 1/√N convergence, the curse of dimensionality, uncertainty propagation
Los Angeles and Los Alamos, 1946
Stanisław Ulam, a Polish mathematician working at Los Alamos, is recovering from a serious illness. To pass the time he plays Canfield solitaire, and he begins to wonder: what is the chance that a randomly dealt game can be won? He tries to count the possibilities combinatorially and gets nowhere.
Then he has the idea that changes scientific computing. It would be much simpler, he realises, to deal out a hundred games, play them, and count the wins. And the same trick could answer questions at Los Alamos that no formula could — how neutrons scatter, split and multiply through layers of material, each one following a random path.
He describes the idea to John von Neumann, who sees at once how to do it on the new electronic computers; by 1948 ENIAC is running neutron-transport calculations by random sampling. Their colleague Nicholas Metropolis names the method after the casino in Monaco where Ulam's uncle liked to gamble. In 1949 Metropolis and Ulam publish The Monte Carlo Method.
Any integral can be written as an expected value. If is uniformly distributed over a region of volume , then
Draw random points, average the function, multiply by the volume. More generally, if has density , : the mean, variance or failure probability of any quantity computed from random inputs is an integral, and sampling estimates it.
💡The 1/√N law
By the central limit theorem, the error of the sample mean is approximately normal with standard deviation
Two consequences. It is slow: a hundred times more samples for one more digit — estimating π from random points, gives an error of about , where Simpson's rule on a 1-D integral would give fourteen digits. It does not depend on the dimension: never appears. A product rule with points per axis needs evaluations and its accuracy per evaluation degrades as grows — the curse of dimensionality. In ten dimensions, a grid with only 10 points per axis already needs evaluations; Monte Carlo estimates the volume of the 10-dimensional unit ball to 2% with . And the error bar comes free: estimate from the samples themselves.
Derivation
Where comes from
Let for independent random points, each with mean (the integral we want, divided by ) and variance . The estimate is their average, .
It is right on average: .
Its spread. Variances of independent quantities add, and scaling by scales a variance by :
Nothing in this calculation mentions the dimension of . The central limit theorem adds that is approximately normally distributed, so about 95% of runs land within of the truth.
For π. Each point contributes if it lands inside the quarter circle (probability ) and 0 otherwise. Its variance is , so — the constant printed by the lab.
📐Uncertainty propagation
A cantilever's tip deflection is , nominally 10.00 mm. The load is uncertain by 10%, the length by 0.5%, the modulus by 5%. Sample 200,000 sets of inputs, compute for each: mean 10.01 mm, standard deviation 1.13 mm, 99th percentile 12.76 mm, and the probability of exceeding the serviceability limit mm is 4.3%. A first-order (linearised) analysis gives the same standard deviation, 1.13 mm — but only sampling gives the tail probability directly, and only sampling still works when the model is a nonlinear finite-element run with no formula at all.
Derivation
The first-order estimate, step by step
For small independent input errors, linearise the model: . Independent variances add (as in the derivation above), each multiplied by the square of its sensitivity:
For a product of powers like this is neatest in relative terms. Taking logarithms, , so a relative change . The relative standard deviations then combine as
On the nominal 10.00 mm that is 1.128 mm — the lab's first-order value. The length is the most precise input yet still contributes, because it enters cubed. Lesson 12-2 writes the same rule for vectors as .
The mathematicians know a great deal about very little and the physicists very little about a great deal.
Variance reduction. Since the error is , reducing is worth as much as increasing :
- Antithetic variates: pair each sample with its mirror image; errors partly cancel for monotone models.
- Stratified and Latin hypercube sampling: force samples to cover every part of each input's range evenly. Standard in engineering reliability studies.
- Importance sampling: sample more often where the integrand is large — near the failure region when estimating a failure probability — and correct with weights.
- Quasi-Monte Carlo: replace random points with low-discrepancy sequences (Sobol, Halton) that fill space more evenly, approaching convergence for smooth integrands.
And all of it depends on the quality of the random numbers themselves — a subject for Unit 12.
💡Where you will use this
Geotechnical and Structural reliability: probabilities of failure with uncertain soil strength, loads and material properties. Orbital Mechanics: collision probability and dispersion of re-entry footprints. Rocket Propulsion and Guidance: Monte Carlo dispersion analysis of trajectories — every launch-vehicle flight is cleared with thousands of simulated flights. GNSS and Navigation: particle filters represent probability distributions by samples.
📚Further reading
- Art Owen, Monte Carlo Theory, Methods and Examples (2013) — a free online book on sampling, variance reduction and quasi-Monte Carlo, by one of the field's leading researchers.
- Nicholas Metropolis and Stanisław Ulam, 'The Monte Carlo method', Journal of the American Statistical Association 44(247), 335–341 (1949) — the paper that named it.
- Michael Heath, Scientific Computing: An Introductory Survey (2nd ed.; SIAM Classics 2018), chapter 13, 'Random Numbers and Stochastic Simulation'.
↓But there is a problem
Everything in this unit computed integrals of given functions. The most important integrals in engineering are not of functions we know, but of laws we know: Newton's second law, the rate equations of a combustion chamber, the attitude dynamics of a spacecraft. A differential equation tells us how the state changes at every instant; integrating it forward in time gives the trajectory.
In 1768 Leonhard Euler proposed the simplest possible way to do it: take the rate of change now, and step forward a little. Most of what comes after — Runge, Kutta, Adams, Gear and every ODE solver in SciPy — is a story of making that step smarter.