function E=Ising_Energy(lattice,i,j,rneigh)
H=2; ## applied magnetic field times permeability[joule]
E=0; ## initial configuration energy[joule]
J0=1 ## coupling constant of function J, normaly in joule.
alpha=2 ## exponential constant of function J.
L=length(lattice); ## number of particles or spins in lattice
for r=1:rneigh
NN1=mod(j+r,L); NN1+=(NN1==0)*L;
NN2=mod(j-r,L); NN2+=(NN2==0)*L;
NN3=mod(i+r,L); NN3+=(NN3==0)*L;
NN4=mod(i-r,L); NN4+=(NN4==0)*L;
J=coupling(rneigh,J0,alpha);
dE=J*(lattice(i,NN1)+lattice(i,NN2)+
lattice(NN3,j)+lattice(NN4,j))-H*(sum((rand(L)>0.5)*2-1));
E+=-1*dE
endfor
endfunction
Comments
Post a Comment