Mathematics.

numerical integration

Monte Carlo Integration

Numerical Analysis30 minDifficulty5 out of 10

You should know: monte carlo methods, numerical integration

Overview

Monte Carlo integration estimates a definite integral by averaging the integrand at random sample points rather than evaluating it on a fixed grid, as the trapezoidal or Simpson's rules do. For ∫ₐᵇ f(x) dx, the estimate is (b−a) times the average of f at N points drawn uniformly at random from [a, b]. This is a direct consequence of the law of large numbers — the sample mean of f converges to the true average of f over the interval as N grows — and the error shrinks like 1/√N regardless of the number of dimensions, unlike grid-based quadrature rules whose cost explodes exponentially with dimension (the 'curse of dimensionality'). This dimension-independence is precisely why Monte Carlo integration is the method of choice for high-dimensional integrals in computational physics, finance (option pricing), and Bayesian statistics, even though its 1/√N convergence is slower than a grid method in low dimensions.

Intuition

Suppose you want the average height of everyone in a large stadium, but can't measure everyone. Instead, you measure a random sample of people and average their heights — by the law of large numbers, that sample average approaches the true average as the sample grows, regardless of the (huge) size of the crowd. Estimating ∫ₐᵇ f(x) dx is exactly this: the true value of the integral is (b−a) times the average value of f over the interval, so measuring f at random points and averaging estimates that average value directly. The key payoff shows up in higher dimensions: to estimate an integral over a d-dimensional region with a grid, the number of grid points needed to keep the same resolution grows exponentially in d, but a random sample of N points needs no grid at all — its error depends only on N, not on d, which is why physicists reach for Monte Carlo methods once dimension climbs past a handful of variables.

Formal Definition

Definition

For f integrable on [a, b], draw N independent samples x₁, …, x_N uniformly from [a, b] and estimate the integral by the scaled sample mean of f:

abf(x)dx(ba)1Ni=1Nf(xi),xiUniform(a,b)\int_a^b f(x)\,dx \approx (b-a)\cdot \dfrac{1}{N}\sum_{i=1}^{N} f(x_i), \qquad x_i \sim \text{Uniform}(a,b)
Monte Carlo integral estimator
σI^(ba)σfN,σf2=1Nif(xi)2(1Nif(xi))2\sigma_{\hat I} \approx (b-a)\,\dfrac{\sigma_f}{\sqrt{N}}, \qquad \sigma_f^2 = \dfrac{1}{N}\sum_i f(x_i)^2 - \Big(\dfrac{1}{N}\sum_i f(x_i)\Big)^2
Standard error of the estimate (falls as 1/√N)

Worked Examples

  1. Evaluate f(x) = x² at each sample point.

    f(0.1)=0.01, f(0.4)=0.16, f(0.6)=0.36, f(0.8)=0.64, f(0.95)=0.9025f(0.1)=0.01,\ f(0.4)=0.16,\ f(0.6)=0.36,\ f(0.8)=0.64,\ f(0.95)=0.9025
  2. Average the 5 function values.

    fˉ=0.01+0.16+0.36+0.64+0.90255=2.07255=0.4145\bar f = \dfrac{0.01+0.16+0.36+0.64+0.9025}{5} = \dfrac{2.0725}{5} = 0.4145
  3. Scale by (b − a) = (1 − 0) = 1 to get the estimate.

    I^=(10)(0.4145)=0.4145\hat I = (1-0)(0.4145) = 0.4145
  4. Compare to the exact value.

    01x2dx=130.3333\int_0^1 x^2\,dx = \tfrac{1}{3} \approx 0.3333

Answer: Monte Carlo estimate ≈ 0.4145 vs exact 1/3 ≈ 0.3333 — a sizable gap with only 5 samples, illustrating why the method needs many samples (typically thousands or more) before the 1/√N error becomes small.

Practice Problems

Difficulty 4/10

Using the 3 sample points x = 0.2, 0.5, 0.9 for f(x) = x², estimate ∫₀¹ x² dx by Monte Carlo integration.

Difficulty 5/10

If the Monte Carlo standard error at N = 100 samples is 0.05, approximately what is the standard error at N = 10,000 samples (same integrand and interval)?

Difficulty 7/10

A physicist needs to compute a 6-dimensional integral for a statistical mechanics partition function. Explain why Monte Carlo integration is preferred over a grid-based method like the composite trapezoidal rule extended to 6 dimensions.

Quiz

The basic Monte Carlo estimator for ∫ₐᵇ f(x) dx is:
The standard error of the Monte Carlo estimate shrinks with sample size N as:
The main reason Monte Carlo integration is preferred for high-dimensional integrals is that:

Summary

  • Monte Carlo integration estimates ∫ₐᵇ f(x) dx as (b−a) times the average of f at N random points in [a,b], using the law of large numbers.
  • For f(x)=x² on [0,1], 5 sample points (0.1, 0.4, 0.6, 0.8, 0.95) give an estimate of 0.4145 versus the exact value 1/3 ≈ 0.3333; the error shrinks toward 0 as N grows.
  • The standard error decreases as O(1/√N), independent of the dimension of the integration domain — unlike grid-based methods whose cost grows exponentially with dimension.
  • This dimension-independence makes Monte Carlo integration the standard tool for high-dimensional integrals in physics, finance, and Bayesian statistics.

References

  1. BookPress, W. H. et al. Numerical Recipes: The Art of Scientific Computing, 3rd ed. Cambridge, 2007.