diff --git a/Images/MCS_diif_L.png b/Images/MCS_diif_L.png new file mode 100644 index 0000000..6872cb0 Binary files /dev/null and b/Images/MCS_diif_L.png differ diff --git a/InitEnergy.py b/InitEnergy.py new file mode 100644 index 0000000..52678c1 --- /dev/null +++ b/InitEnergy.py @@ -0,0 +1,18 @@ +def Ener(ising,L,J): + E=0 + M=0 + for i in range (L): + for j in range (L): + a,b,c,d=i+1,i-1,j+1,j-1 + if i==L-1: + a=0 + if i==0: + b=L-1 + if j==L-1: + c=0 + if j==0: + d=L-1 + + M+=ising[i][j] + E=E-J*float(ising[i][j]*(ising[a][j]+ising[b][j]+ising[i][c]+ising[i][d])) + return (M,E) \ No newline at end of file diff --git a/LatticeLen.py b/LatticeLen.py new file mode 100644 index 0000000..a8da6b6 --- /dev/null +++ b/LatticeLen.py @@ -0,0 +1,35 @@ +import numpy as np +import matplotlib.pyplot as plt +from RandomSpin import randomIsing +from InitEnergy import Ener +from Montecarlo import MCS +T=1.4 +J=1 +Len=[] +for L in range(10,40,10): + ising=randomIsing(L) + M,E=Ener(ising,L,J) + print(M,E) + E*=0.5 + N=100000 + # ener=[] + mag=[] + for n in range(N): + ising,E,M=MCS(ising,L,T,J,E,M) + # enspin=E/(L*L) + Mspin=M/(L*L) + + # ener.append(enspin) + mag.append(Mspin) + + Len.append(mag) + +num=np.arange(0,n+1,1) +plt.plot(num,Len[0],color='r',label='L=10') +plt.plot(num,Len[1],color='g',label='L=20') +plt.plot(num,Len[2],color='b',label='L=30') +plt.title('M/N vs MCS') +plt.xlabel('MCS') +plt.ylabel('M/N') +plt.legend() +plt.show() \ No newline at end of file diff --git a/Montecarlo.py b/Montecarlo.py new file mode 100644 index 0000000..4881f1b --- /dev/null +++ b/Montecarlo.py @@ -0,0 +1,36 @@ +import numpy as np +def MCS(ising,L,T,J,E,M): + for k in range(L): + for l in range (L): + r=np.random.uniform(0,1) + i=int(r*(L-1)) + t=np.random.uniform(0,1) + j=int(t*(L-1)) + a,b,c,d=i+1,i-1,j+1,j-1 + if i==L-1: + a=0 + if i==0: + b=L-1 + if j==L-1: + c=0 + if j==0: + d=L-1 + Ei=-J*float(ising[i][j]*(ising[a][j]+ising[b][j]+ising[i][c]+ising[i][d])) + ising[i][j]=-ising[i][j] + Ef=-J*float(ising[i][j]*(ising[a][j]+ising[b][j]+ising[i][c]+ising[i][d])) + dE=Ef-Ei + + if(dE<=0.0): + E+=dE + M+=(2.0*float(ising[i][j])) + else: + u=np.exp(-dE/T) + h=np.random.uniform(0,1) + if(h=k: - total.append(energy(n)) - - n1=n - else: - #total.append(energy(n1)) - - n1=n1 - - - # E=total[3000:-1] - avgenergy=np.mean(total) - P.append(avgenergy) - -temp=np.arange(1,499,1) -# plt.plot(temp,P) -# plt.show() -f=np.copy(P[1:len(P)]) -r=np.copy(P[0:len(P)-1]) - -d=r-f -plt.plot(temp,d) -plt.show() - - diff --git a/test2.py b/test2.py deleted file mode 100644 index e2f1828..0000000 --- a/test2.py +++ /dev/null @@ -1,43 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt -t=100000 -hbar = 1.0545718e-34 # Planck's constant / 2*pi -k_B = 1.380649e-23 # Boltzmann constant -m = 1e-26 # mass of oscillator -omega = 1e9 # frequency of oscillator -def energy(n): - y= ((n+(1/2))*hbar*omega) - return(y) - -def prob(n): - y=np.exp(-energy(n)/(k_B*300)) - return(y) - - -n1=0 -total=[] -ener=0 -for i in range (1,t): - n=np.random.randint(0,1000) - if energy(n)<=energy(n1): - ener+=energy(n)/i - total.append(energy(n)) - - n1=n - else: - k=np.random.uniform(0,1) - R=prob(n)/prob(n1) - if R>=k: - ener+=energy(n)/i - total.append(energy(n)) - - n1=n - else: - ener+=energy(n1)/i - total.append(energy(n1)) - - n1=n1 - -num=np.arange(1,t,1) -plt.plot(num,total) -plt.show() diff --git a/test3.py b/test3.py deleted file mode 100644 index b9bec43..0000000 --- a/test3.py +++ /dev/null @@ -1,49 +0,0 @@ -import numpy as np -import matplotlib.pyplot as plt -N=10000 -hbar = 1.0545718e-34 # Planck's constant / 2*pi -k_B = 1.380649e-23 # Boltzmann constant -m = 1e-26 # mass of oscillator -omega = 1e9 # frequency of oscillator -def energy(n): - y= ((n+(1/2))*hbar*omega) - return(y) -tot=[] -for j in range(1,300): - T=j - n1=0 - t=0 - E=np.zeros(N) - for i in range (N): - n=np.random.randint(0,100) - if energy(n)<=energy(n1): - E[i]=energy(n) - - - n1=n - else: - k=np.random.uniform(0,1) - R= np.exp( -(n - n1) / k_B*T ) - if R>=k: - E[i]=energy(n) - n1=n - - - else: - - #E[i]=energy(n) - n1=n1 - - total=np.mean(E) - tot.append(total) - -temp=np.arange(1,300,1) -plt.plot(temp,tot) -plt.show() - - - - - - - \ No newline at end of file