Each arrow is a spin sᵢ = ±1 sitting on a square lattice. Its energy comes from the Ising Hamiltonian: neighboring spins interact through an exchange coupling J, and every spin also feels an external field H. A Metropolis Monte Carlo loop repeatedly picks a random spin, computes the energy change ΔE a flip would cost, and always accepts flips that lower the energy — flips that raise it are accepted only with probability e^(−ΔE/T). At low temperature this settles into large aligned domains; near the critical temperature Tc ≈ 2.27 (in units of J/k) domains fragment and reorganize; at high temperature thermal noise wins and the lattice looks random.
H = −J Σ⟨i,j⟩ sᵢsⱼ − H Σᵢ sᵢ
ΔE = 2sᵢ(J·Σ_neighbors + H)
P(flip) = min(1, e^(−ΔE/T))
- Ferromagnetic / Antiferromagnetic — sets the sign of J. J>0 rewards aligned neighbors and grows solid-color domains; J<0 rewards opposite neighbors and grows a checkerboard pattern.
- Temperature T — how much random thermal flipping fights the ordering tendency; sweep it across Tc ≈ 2.27 to watch domains melt or freeze.
- External field H — biases spins toward +1 (H>0) or −1 (H<0), the mechanism behind hysteresis in real ferromagnets.
- Randomize spins — reshuffle the lattice to a random start, useful for watching ordering happen from scratch at the current T and H.
Real-world relevance: this same lattice model — with its exchange interaction, thermal competition and critical temperature — is the standard textbook explanation for how iron, cobalt and nickel form magnetic domains, why they lose magnetism above their Curie point, and why antiferromagnets like MnO show no net magnetization even though every spin is perfectly ordered.