Skip to content
Math Visualizer
Statistical mechanicsintermediate

Ising Model

Tiny magnets on a grid try to align with their neighbors while heat flips them at random. Cool the grid below the critical temperature, about 2.269, and it magnetizes.

What this shows

Each square is a spin, a tiny magnet that points either up or down, shown in two contrasting colors (orange and blue in the Classic palette). Neighboring spins lower their energy by pointing the same way, while temperature flips them at random. Which effect wins depends on the temperature TT:

  • Below the critical temperature Tc≈2.269T_c \approx 2.269, alignment wins. Regions of one color grow, and given enough time one color takes over: the grid is magnetized.
  • Above TcT_c, the random flips win. Small patches appear and vanish, and on average half the spins point each way.
  • Near TcT_c, patches of every size appear at once, from single spins to regions nearly as large as the grid.

The corner shows the temperature and the magnetization per spin mm, the average of all spins (+1 for up, −1 for down).

Things to try: start just above TcT_c (the default), then drag the temperature down to 1.5 and watch the regions grow and their boundaries straighten. Or start with every spin up and raise the temperature past TcT_c.

How the visualization works

  • Spins are updated with the Metropolis algorithm. Each attempt picks a spin at random and works out how much flipping it would change the energy, ΔE\Delta E. If the energy would not go up, the spin flips. Otherwise it flips with probability e−ΔE/Te^{-\Delta E/T}, so energy-raising flips are rare when it's cold and common when it's hot.
  • One sweep is as many attempts as there are spins, so each spin gets one attempt on average.
  • The grid wraps around: spins on the right edge are neighbors of spins on the left edge, and the same for top and bottom. No spin sits on a boundary.
  • All randomness comes from a seeded pseudo-random generator. The two flip probabilities are computed with only addition, subtraction, multiplication and division, which every browser must round the same way (the built-in exponential function has no such guarantee). A shared link therefore replays exactly.
  • The simulation runs in a Web Worker. The largest grid has 262,144 spins, so a single sweep is far too much work for the page's own thread at high speed. If a device can't keep up, the simulation runs slower than requested instead of freezing the page.

Parameters

  • Grid size: spins along each side. Restarts the run.
  • Temperature: applies immediately, from the next sweep. A shared link replays the run from the start at the temperature in the link, so changes made during a run are not part of it.
  • Starting spins: random (as if infinitely hot) or all up (as if at absolute zero). Restarts the run.
  • Speed: sweeps per second. Applies immediately and never changes the results.

Mathematical background

A configuration assigns si=+1s_i = +1 or −1-1 to every site ii. Its energy is

H=−∑⟨i,j⟩sisj,H = -\sum_{\langle i, j \rangle} s_i s_j,

summed over all pairs of neighboring sites. Each aligned pair contributes −1 and each opposed pair +1. At temperature TT, a configuration occurs with probability proportional to e−H/Te^{-H/T} (the Boltzmann distribution). At low temperatures the low-energy, aligned configurations dominate; at high temperatures every configuration is almost equally likely. The Metropolis algorithm is a Markov chain whose long-run distribution is exactly this one, which is why it is used to sample it.

Ernst Ising solved the one-dimensional chain in 1925 and found no phase transition at any positive temperature. In two dimensions there is one. Lars Onsager solved the square-lattice model exactly in 1944, with the transition at

Tc=2ln⁡(1+2)≈2.269.T_c = \frac{2}{\ln\bigl(1 + \sqrt{2}\bigr)} \approx 2.269.

C. N. Yang later derived the magnetization below TcT_c:

m=(1−sinh⁡−4(2/T))1/8,m = \bigl(1 - \sinh^{-4}(2/T)\bigr)^{1/8},

about 0.986 at T=1.5T = 1.5 and 0.911 at T=2T = 2. It falls to zero at TcT_c very steeply, and stays zero above it.

A finite grid differs from these infinite-lattice results in a few ways you can see:

  • Up and down are symmetric, so which color wins from a random start is a matter of chance.
  • Starting from random spins below TcT_c, the regions grow slowly, roughly like the square root of the number of sweeps. Stripes that wrap all the way around the grid can last a very long time.
  • Near TcT_c, large regions take many sweeps to change. This critical slowing down is a property of single-spin algorithms like Metropolis, not of the model itself.

References

Full citations for Ising (1925), Onsager (1944), Yang (1952) and Metropolis et al. (1953) are listed below.

  1. E. Ising. Beitrag zur Theorie des Ferromagnetismus (1925). Zeitschrift für Physik 31, 253–258. Solves the one-dimensional model, which has no phase transition.
  2. L. Onsager. Crystal Statistics. I. A Two-Dimensional Model with an Order-Disorder Transition (1944). Physical Review 65, 117–149. The exact solution on the square lattice, with its transition at T_c = 2/ln(1 + √2).
  3. C. N. Yang. The Spontaneous Magnetization of a Two-Dimensional Ising Model (1952). Physical Review 85, 808–816. The magnetization below T_c.
  4. N. Metropolis, A. W. Rosenbluth, M. N. Rosenbluth, A. H. Teller and E. Teller. Equation of State Calculations by Fast Computing Machines (1953). The Journal of Chemical Physics 21, 1087–1092. The sampling algorithm used here.