# Mean field gen d Ising lattice.py

(Difference between revisions)
 Revision as of 12:06, 8 November 2016Werner (Talk | contribs)← Previous diff Revision as of 16:01, 8 November 2016Werner (Talk | contribs) Next diff → Line 30: Line 30: pylab.savefig('mean_field_gen_d_Ising.png') pylab.savefig('mean_field_gen_d_Ising.png') pylab.show() pylab.show() + + [[Category:ICFP Lectures]]

## Revision as of 16:01, 8 November 2016

```import math, random, pylab

dim = 2

L = 100
N = L ** dim
Tc = 2 * dim

neighbours_all = [[site + ((site // L ** ind + i) % L -
(site // L ** ind) % L) * L ** ind
for ind in range(dim)
for i in [1, -1]]
for site in range(N)]

t = 0.01
beta = (t * Tc + Tc) ** (-1)
m = [1.0] * N
print 'Temperature = ', 1.0 / beta
for iter in range(1000 * N):
i = random.randint(1, N - 1)
m[i] =  math.tanh(beta * sum(m[k] for k in neighbours_all[i]))
x_vec = range(L)
y_vec = [abs(m[k]) for k in range(L)]
pylab.title('Mean-field lattice self-consistency, \$L, d, T =\$ ' + str(L) + ' ' +
str(dim) + ' ' + str(1 / beta))
pylab.semilogy(x_vec, y_vec)
pylab.xlabel('\$k\$ (Lattice site in \$(1,0,0)\$ direction) ', fontsize=18)
pylab.ylabel('\$m(k)\$ (spin magnetization)', fontsize=18)
pylab.legend(loc='lower left')
pylab.savefig('mean_field_gen_d_Ising.png')
pylab.show()
```