# Ising mean field 1d.py

(Difference between revisions)
 Revision as of 22:13, 6 November 2016Werner (Talk | contribs)← Previous diff Current revisionWerner (Talk | contribs) Line 1: Line 1: - 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. + 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. Two following approaches are used: On the one hand the true self-consistency, and on the other the linearized version. Line 14: Line 14: for iter in range(100000): for iter in range(100000): for i in range(1, length): for i in range(1, length): - m_vec[i] = beta * (m_vec[i-1] + m_vec[i+1]) + m_vec[i] = beta * (m_vec[i - 1] + m_vec[i + 1]) - pylab.semilogy(x_vec, m_vec[0:length],label='lin' + str(t)) + pylab.semilogy(x_vec, m_vec[0: length],label='lin' + str(t)) for iter in range(100000): for iter in range(100000): for i in range(1, length): for i in range(1, length): - m_vec[i] = math.tanh( beta * (m_vec[i-1] + m_vec[i+1])) + 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.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.title('Mean-field self-consistency 1-d Ising model, \$m(0)=1\$, \$m(L) = 0\$') Line 26: Line 26: pylab.savefig('mean_field_1d_Ising.png') pylab.savefig('mean_field_1d_Ising.png') pylab.show() pylab.show() + + [[Category:ICFP Lectures]]

## Current revision

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. Two following 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()
```