Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.51 KB | None | 0 0
  1. from random import randint
  2. from random import random    
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5. A=[]
  6. K=[]
  7. temp_analitico=[]
  8.  
  9. def my_range(start, end, step):
  10.     while start <= end:
  11.         yield start
  12.         start += step
  13.  
  14. def cc(k,tam):
  15.     if k > tam-1:
  16.         return 0
  17.     if k < 0:
  18.         return tam-1
  19.     else:
  20.         return k
  21.  
  22. def energia(sistema, N, M, tam):
  23.     t=cc(N-1,tam)
  24.     u=cc(N+1,tam)
  25.     v=cc(M-1,tam)
  26.     x=cc(M+1,tam)
  27.     a=sistema[N,M] * (sistema[t, M]+ sistema[u, M] + sistema[N, v] + sistema[N, x])
  28.     return a
  29.  
  30.  
  31. #######magnteizaçao###########3
  32. def magntotal(sistema,tam):
  33.     M=0
  34.  
  35.     for i in range(tam):
  36.         for j in range(tam):
  37.             M+=sistema[i,j]
  38.     return M   
  39.  
  40. def main(T, tam, sweep):
  41.  
  42.     system=[]
  43.     sistema=[]
  44.     autocorrelacao=[]
  45.  
  46.     for x in range(tam):
  47.         m=[]
  48.  
  49.         for y in range(tam):
  50.             m.append(1)
  51.  
  52.         system.append(m)   
  53.  
  54.     sistema=np.array(system)
  55.    
  56.    
  57.  
  58.     for i in range(sweep):
  59.  
  60.         M = randint(0,tam-1)
  61.         N = randint(0,tam-1)
  62.        
  63.         deltaE =2*energia(sistema, N, M, tam)
  64.      
  65.         if deltaE <= 0.:
  66.             sistema[N,M] *= -1 
  67.  
  68.         elif np.exp((-1/T)*deltaE) > random():
  69.             sistema[N,M] *= -1
  70.    
  71.     Mag=magntotal(sistema,tam)
  72.  
  73.     for i in range(sweep):
  74.         for j in range(tam**2):
  75.  
  76.             M = randint(0,tam-1)
  77.             N = randint(0,tam-1)
  78.        
  79.             deltaE =2*energia(sistema, N, M, tam)
  80.  
  81.  
  82.      
  83.             if deltaE <= 0.:
  84.  
  85.                 sistema[N,M] *= -1 
  86.                 Mag+=2*sistema[N,M]/tam**2
  87.  
  88.             elif np.exp((-1/T)*deltaE) > random():
  89.  
  90.                 sistema[N,M] *= -1
  91.                 Mag+=2*sistema[N,M]/tam**2
  92.  
  93.         autocorrelacao.append(Mag)
  94.    
  95.     return autocorrelacao
  96.  
  97. def my_range(start, end, step):
  98.     while start <= end:
  99.         yield start
  100.         start += step
  101.  
  102. ################## início ##################
  103. k=0
  104. tau=[]
  105. t=[]
  106.  
  107. for tam in my_range(20,20,5):
  108.  
  109.     correlacao=[]
  110.     T=2.4
  111.     res=main(T,tam,100)
  112.     length=np.size(res)
  113.     L=[]
  114.     L.append(tam)
  115.  
  116.     for i in range (np.size(res)):
  117.         k=0
  118.  
  119.         for j in range (np.size(res)-i):
  120.             k+=res[j]*res[j+i]
  121.             t.append(i)
  122.             correlacao.append(k/((res[0])*(length-i)))
  123.        
  124.     tau.append(np.trapz(correlacao))
  125.  
  126.     plt.plot(t,correlacao,'r')
  127.     plt.show()
  128.  
  129. plt.plot(L,tau,'b')
  130. plt.xscale('log')
  131. plt.yscale('log')
  132. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement