Assignment2 210121004 Final
Assignment2 210121004 Final
For studying physical phase transitions, the Hamiltonian the system of spins follows is:
H = −J∑<i,j> SiSj −μH∑i Si which in presence of no magnetic field
i.e. H = 0, reduces to :
H = −J∑<i,j> SiSj
Note that we consider only nearest neighbour interaction
Em
and, Mm = ∑i Sj(m)
both these quantities can be averaged over for different values of temperature to find heat
capacity C and magnetic susceptibility χ, using the below formulas, which will show sharp
transitions with temperature, supporting our original claim of phase transition and help us in
estimating a transition critical temperature Tc.
Step 1: Initialization
We define the function "lattice" which takes the size of the lattice as the input and generates
the required 2D Lattice of spins. The spins can take values 1 or -1 which are uniformly
distributed over the entire lattice.
In [19]:
def energy(conf): energy = 0
for i in range(len(conf)):
for j in range(len(conf)):
S = conf[i,j]
nb = conf[(i+1)%N, j] + conf[i,(j+1)%N] + conf[(i-1)%N, j] + conf[i,(j
energy += -nb*S return energy/4.
In [21]: nt = 100 N
= 16 eqSteps =
1024 mcSteps =
1024
for i in range(mcSteps):
switch(config, 1/T[t])
Ene = energy(config) # calculate the energy
Mag = mag(config) # calculate the magnetisation
E1 = E1 + Ene
M1 = M1 + Mag
M2 = M2 + Mag*Mag
E2 = E2 + Ene*Ene
E[t] = n1*E1
M[t] = n1*M1
C[t] = (n1*E2 - n2*E1*E1)/(T[t]**2)
X[t] = N*N*(n1*M2 - n2*M1*M1)/T[t]
In [ ]: