# 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:

$E=-J\sum_i\sum_k S_iS_k-B\sum S_k$

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

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