Monte Carlo Sampling
Monte Carlo Simulation in Statistical Mechanics
The Core Idea: Sampling Phase Space
In contrast to molecular dynamics (MD) — where the system follows a deterministic trajectory through phase space — Monte Carlo (MC) simulation directly samples points in phase space according to a target probability density. The key insight is that the probability density approaches a stationary solution (the equilibrium distribution). By sampling phase space according to this density, equilibrium properties can be computed without following time evolution.
This approach is fundamentally a method of integration, not a simulation technique in the traditional sense. Even when calculating thermodynamic properties, those properties derive from integrals over phase space (like the partition function). Monte Carlo evaluates those integrals. The method is purely mathematical and can be applied far beyond thermodynamics to any integration problem.
The Mathematical Problem: The Canonical Ensemble
In the canonical ensemble (NVT), the partition function is:
where β=1/kBT.
In classical mechanics, the phase space of N particles is continuous (with 3N position coordinates q and 3N momentum coordinates p). The Hamiltonian H(q,p) is a continuous function, and the sum becomes an integral:
This is a 6N-dimensional integral. For N∼1023, the dimensionality is astronomical.
Monte Carlo simulation is a statistical method to evaluate high-dimensional integrals by random sampling, focusing computational effort on regions where the integrand is large.
The Impossibility of Traditional Quadrature
A naive approach would be to discretize each variable into M grid points and use a quadrature rule (trapezoidal, Simpson's, Gaussian quadrature). For a 1D integral:
For 2 variables, an M×M grid is needed. For 6N variables, the total number of grid points is:
Even with N=100 (a tiny system), M6N is astronomically large — impossible on any computer. Additionally, the integrand e−H/kBT is vanishingly small for most phase-space points (where H is large). Wasting computational effort on such points makes quadrature doubly impractical.
Monte Carlo Integration: A Simple Example — Computing π
The classic demonstration of Monte Carlo integration is computing π by estimating the area of a unit circle (area=π).
The Setup
Consider a unit circle x2+y2=1. The area of the quadrant in the first quadrant is:
Instead of evaluating this integral directly, construct a unit square (0≤x≤1, 0≤y≤1) that encloses the quadrant.
The Method
Generate random points (x,y) uniformly within the unit square.
Count how many points satisfy x2+y2≤1 (inside the quadrant).
The ratio of points inside the quadrant to total points approximates the area of the quadrant divided by the area of the square (which is 1):
Hence:
Why It Works
This is a numerical experiment akin to throwing darts at a dartboard. The probability of hitting inside a region is proportional to the region's area (when the dartboard is uniformly random). With enough points, the ratio converges to the true area ratio.
Accuracy
With 10 points: rough estimate (~3.0)
With 100 points: first decimal (~3.1)
With 1,000 points: two decimals (~3.14)
With 106 points: three to four decimals correct
The error decreases as 1/N, independent of dimensionality. This is the key advantage of Monte Carlo over quadrature for high dimensions.
Random Sampling vs. Importance Sampling
Random (Uniform) Sampling
In the simple π example, points are generated uniformly over the integration domain. This is the most basic form of Monte Carlo integration. For an integral:
Generate N random points xi uniformly in [a,b]. The estimator is:
But this is inefficient when f(x) is sharply peaked or has large regions where it is nearly zero — as in the Boltzmann factor e−H/kBT over phase space.
Importance Sampling
The central idea: focus sampling where the integrand is large. Rewrite the integral as:
where ρ(x)≥0 is a probability density from which points are drawn (not uniformly). The estimator becomes:
Here, xi are sampled from ρ(x).
If ρ(x) is proportional to f(x), the ratio f(x)/ρ(x) is nearly constant — low variance, high efficiency.
Regions where f(x) is small are sampled rarely (small ρ), saving effort.
Regions where f(x) is large are sampled frequently (large ρ), ensuring accuracy.
Importance sampling makes Monte Carlo an intelligent exploration method for phase space. Without it, random sampling would fail for thermodynamic systems because the Boltzmann factor is negligible over most of phase space.
Application to Thermodynamics
For the canonical partition function integral:
The integrand e−H/kBT is sharply peaked around low-energy configurations (due to the exponential). Importance sampling means generating configurations with probability ∝e−H/kBT — the Boltzmann distribution itself. This ensures that most sampled points significantly contribute to the integral.
How to generate such configurations? Through a Markov chain — propose moves (changes in coordinates) and accept/reject them using a criterion that maintains detailed balance (e.g., the Metropolis algorithm). This is the core of practical Monte Carlo simulations in statistical mechanics.
Key Takeaways
Monte Carlo is a method of integration, not a dynamic simulation. It is especially suited for high-dimensional integrals where quadrature fails.
The curse of dimensionality makes traditional grid-based integration impossible for systems with many particles — Monte Carlo avoids this by scaling as 1/N regardless of dimension.
Random sampling is the simplest form but wastes effort where the integrand is small.
Importance sampling concentrates computational resources on important regions of phase space, making Monte Carlo efficient and powerful for thermodynamic problems.
Importance sampling requires generating points according to the Boltzmann distribution — this is achieved through Markov chain algorithms like Metropolis.

Ask anything
We've read this whole study set, so questions about it get the best answers.