Ising mean field 1d.py
From Werner KRAUTH
This is the Python program which computes the self-consistent solution for a one-dimensional chain of Ising spins, where we put the spin at k=0 equal to 1. To approaches are used: On the one hand the true self-consistency, and on the other the linearized version.
import math, numpy, pylab length = 100 m_vec = [0] * (length + 1) x_vec = range(length) m_vec[0] = 1.0 Tc = 2.0 t_vec = [0.0025, 0.01, 0.04, 0.16] for t in t_vec: beta = (t * Tc + Tc) ** (-1) for iter in range(100000): for i in range(1, length): m_vec[i] = beta * (m_vec[i-1] + m_vec[i+1]) pylab.semilogy(x_vec, m_vec[0:length],label='lin' + str(t)) for iter in range(100000): for i in range(1, length): m_vec[i] = math.tanh( beta * (m_vec[i-1] + m_vec[i+1])) pylab.semilogy(x_vec, m_vec[0:length],label='th' + str(t)) pylab.title('Mean-field self-consistency 1-d Ising model, $m(0)=1$, $m(L) = 0$') pylab.xlabel('$k$ (Lattice sites) ', fontsize=18) pylab.ylabel('$m(0)m(k)$ (Mean-field correlation)', fontsize=18) pylab.legend(loc='lower left') pylab.savefig('mean_field_1d_Ising.png') pylab.show()