# Introduction to Mathematical Physics/Statistical physics/Some numerical computation in statistical physics

In statistical physics, mean quantities evaluation can be done using by Monte--Carlo methods. in this section, a simple example is presented.

Example:

Let us consider a Ising model. In this spin system, energy can be written:

${\displaystyle E=-J\sum _{i}\sum _{k}S_{i}S_{k}-B\sum S_{k}}$

The following Metropolis algorithm [ma:compu:Stauffer93], [ma:compu:Koonin90] is used \index{Metropolis} to simulate probabilities ${\displaystyle exp(-E/k_{B}T)}$:

1. select spin ${\displaystyle S_{k}}$ to consider.
2. evaluate variation of energy ${\displaystyle \Delta E=E_{new}-E_{old}}$ associated to a possible split of spin ${\displaystyle S_{k}}$.
3. compare a random number ${\displaystyle z}$ between zero and one with probability ${\displaystyle p=exp(-\Delta E/k_{B}T)}$.
4. split spin number ${\displaystyle k}$ (that is do ${\displaystyle S_{k}=-S_{k}}$) i=f and only if ${\displaystyle z.
5. use the obtained configuration to compute mean quantities.