Add algorithm for the Metropolis algorithm

This commit is contained in:
Cory Balaton 2023-11-26 19:18:26 +01:00
parent 4086e30f6f
commit b5eadd2e56
No known key found for this signature in database
GPG Key ID: 3E5FCEBFD80F432B

23
latex/metropolis.tex Normal file
View File

@ -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}