Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- from random import random
- import numpy as np
- import matplotlib.pyplot as plt
- A=[]
- K=[]
- temp_analitico=[]
- def my_range(start, end, step):
- while start <= end:
- yield start
- start += step
- def cc(k,tam):
- if k > tam-1:
- return 0
- if k < 0:
- return tam-1
- else:
- return k
- def energia(sistema, N, M, tam):
- t=cc(N-1,tam)
- u=cc(N+1,tam)
- v=cc(M-1,tam)
- x=cc(M+1,tam)
- a=sistema[N,M] * (sistema[t, M]+ sistema[u, M] + sistema[N, v] + sistema[N, x])
- return a
- #######magnteizaçao###########3
- def magntotal(sistema,tam):
- M=0
- for i in range(tam):
- for j in range(tam):
- M+=sistema[i,j]
- return M
- def main(T, tam, sweep):
- system=[]
- sistema=[]
- autocorrelacao=[]
- for x in range(tam):
- m=[]
- for y in range(tam):
- m.append(1)
- system.append(m)
- sistema=np.array(system)
- for i in range(sweep):
- M = randint(0,tam-1)
- N = randint(0,tam-1)
- deltaE =2*energia(sistema, N, M, tam)
- if deltaE <= 0.:
- sistema[N,M] *= -1
- elif np.exp((-1/T)*deltaE) > random():
- sistema[N,M] *= -1
- Mag=magntotal(sistema,tam)
- for i in range(sweep):
- for j in range(tam**2):
- M = randint(0,tam-1)
- N = randint(0,tam-1)
- deltaE =2*energia(sistema, N, M, tam)
- if deltaE <= 0.:
- sistema[N,M] *= -1
- Mag+=2*sistema[N,M]/tam**2
- elif np.exp((-1/T)*deltaE) > random():
- sistema[N,M] *= -1
- Mag+=2*sistema[N,M]/tam**2
- autocorrelacao.append(Mag)
- return autocorrelacao
- def my_range(start, end, step):
- while start <= end:
- yield start
- start += step
- ################## inÃcio ##################
- k=0
- tau=[]
- t=[]
- for tam in my_range(20,20,5):
- correlacao=[]
- T=2.4
- res=main(T,tam,100)
- length=np.size(res)
- L=[]
- L.append(tam)
- for i in range (np.size(res)):
- k=0
- for j in range (np.size(res)-i):
- k+=res[j]*res[j+i]
- t.append(i)
- correlacao.append(k/((res[0])*(length-i)))
- tau.append(np.trapz(correlacao))
- plt.plot(t,correlacao,'r')
- plt.show()
- plt.plot(L,tau,'b')
- plt.xscale('log')
- plt.yscale('log')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement