diff --git a/latex/metropolis.tex b/latex/metropolis.tex new file mode 100644 index 0000000..04a6b61 --- /dev/null +++ b/latex/metropolis.tex @@ -0,0 +1,23 @@ +\begin{figure}[H] + \begin{algorithm}[H] + \caption{Metropolis-Hastings Algorithm} + \label{algo:metropolis} + \begin{algorithmic} + \Procedure{Metropolis}{$lattice, energy, magnetization$} + \For{ Each spin in the lattice } + \State $ri \leftarrow \text{random index of the lattice}$ + \State $rj \leftarrow \text{random index of the lattice}$ + \State $dE \leftarrow 2 \cdot lattice_{ri,rj} \cdot (lattice_{ri,rj-1} + lattice_{ri,rj+1} + + lattice_{ri-1,rj} + lattice_{ri+1,rj} )$ + + \State $rn \leftarrow \text{random number} \in [0,1)$ + \If{$rn \leq e^{- \frac{dE}{T}}$} + \State $lattice_{ri,rj} = -1 \cdot lattice_{ri,rj}$ + \State $magnetization = magnetization + 2 \cdot lattice_{ri,rj}$ + \State $energy = energy + dE$ + \EndIf + \EndFor + \EndProcedure + \end{algorithmic} + \end{algorithm} +\end{figure}