The 2D Ising Model Monte Carlo Simulation Using the Metropolis Algorithm

Initializing live version
Download to Desktop

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram Player or other Wolfram Language products.

This Demonstration provides insight into the Monte Carlo algorithm for the 2D Ising model, a 2D system of lattice spins coupled by nearest neighbor interactions. One can visualize how this powerful numerical tool can generate spin configurations and calculate statistical averages for such a system, thus demonstrating the whole range of possible Ising model states: ferromagnetic, anti-ferromagnetic, and non-interacting spins cases.


This Demonstration will explain Monte Carlo simulations with the use of the Metropolis algorithm. It also examines the notion of convergence times and the process of achieving thermal equilibrium.


Contributed by: Darya Aleinikava (August 2011)
Open content licensed under CC BY-NC-SA



The 2D Ising model refers to a 2D square lattice with spins on each site interacting only with their immediate neighbors. The Hamiltonian of a system is


where is the coupling strength and the summation runs over all nearest neighbor pairs. The spin can be in two states: up with and down with . On the plot, and are denoted by black and white colors, respectively. The sign of the constant is very important. corresponds to a ferromagnetic state in which spins tend to align with each other in order to minimize the energy. For , they prefer to be antiparallel and for a simple lattice that leads to a chessboard-like alignment, a feature of the anti-ferromagnetic state. For , spins "do not care", and the alignment is arbitrary. The temperature "blurs" this picture since thermal fluctuation can disrupt a preferred alignment. Hence the final state is determined by the ratio , which serves as one of the controls. Total magnetization is defined as a sum of all spins and is normalized so that for all spins pointing up, , and for all spins pointing down, . Since flipping of all spins simultaneously does not change the system energy, magnetization modulus || is a more valid characteristic and the change that is statistically averaged by as a system progresses is displayed on a graph.

For Monte Carlo simulations the initial spin configuration is to be selected. In this Demonstration it is either a random spin distribution or a fully up-aligned configuration. A single Monte Carlo loop in a spin-flip algorithm consists of the following steps. One randomly chooses a site and contemplates whether a spin should be flipped on this site (such a step is called "proposing an update"). The decision is based on energy considerations and is done by the Metropolis algorithm [1]. If an update is accepted the spin changes as , if not, nothing happens. Then one randomly chooses another site and repeats the procedure. By moving the control "number of steps" one can observe the dynamics of the accepted/rejected updates and the state of the spins that the system prefers. For the "best state" is like a chessboard, so you will see how such a state is constructed. Moving closer to 0 means that either grows or || decreases, so the picture will get more random and at it will be absolutely random since spins do not interact in this case. For one obtains a ferromagnetic configuration, but not until (the point of phase transition) is the interaction large enough to create the aligned domains.

Ideally the simulations run until a system "forgets" the initial configuration, achieves a thermal equilibrium, and you are satisfied with the error of your statistically averaged quantities. Depending on the parameters , initial spin, and the size of the system, it can be either quick or rather long. Therefore for the limited number of steps used in this Demonstration, a different choice of initial configuration yields drastically different results for, say, . In this case for initially fully aligned spins, the flip of a single spin is so energetically costly that it is highly improbable, so you are not likely to see any changes at all. However, for a random initial configuration it is quite possible and you will observe the gradual system alignment resulting in creation of fully magnetized domains. The domain walls are energetically "expensive" but require even higher energy to be destroyed, so in our range of simulations it will probably not happen. Browsing the results obtained with different initial conditions will show that before the system gets to thermal equilibrium, the collected results are often artifacts of the initial condition and algorithm details. This Demonstration is rather useful in portraying this circumstance.

See the online documentation [1].


[1] "Worm Algorithm and Diagrammatic Monte Carlo." (Aug 17, 2011)

Feedback (field required)
Email (field required) Name
Occupation Organization
Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback.