Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. #Importando as Bibliotecas necessárias
  2. import numpy as np # Biblioteca de vetores e matrizes
  3. import matplotlib.pyplot as plt # Biblioteca de plotar gráficos
  4. import matplotlib.pyplot as pltx # Biblioteca de plotar gráficos
  5.  
  6. #Constantes
  7. nt = 100000 # Números de intervalos
  8. dt = 360 # Delta_t(s) => 1h
  9. mt = 5.9742*(10**24) # Massa da Terra(Kg)
  10. ml = 7.36*(10**22) # Massa da Lua(Kg)
  11. ms = 1.9891*(10**30) # Massa do Sol(Kg)
  12. g = 6.67428*(10**-20) # Constante gravitacional(SI) => km3/kg*s2
  13.  
  14. #tt = 31.557.600s #Período da terra em relação ao sol (s) => 365,25 dias => 31.557.600s
  15. #tl= 2.360.880s #Período da lua em relação a terra (s) => 27,325 dias => 2.360.880s
  16.  
  17. #Criando vetores variáveis e zerando OBS: Sol referenciado fixo
  18. t = np.zeros(nt) # Tempo discretizado
  19.  
  20. xt = np.zeros(nt) # Posição horizontal da Terra
  21. yt = np.zeros(nt) # Posição vertical da Terra
  22. vxt = np.zeros(nt) # Velocidade horizontal da Terra
  23. vyt = np.zeros(nt) # Velocidade vertical da Terra
  24. axt = np.zeros(nt) # Aceleração horizontal da Terra
  25. ayt = np.zeros(nt) # Aceleração vertical da Terra
  26.  
  27. rt = np.zeros(nt) # distância do Sol à Terra
  28. rl = np.zeros(nt) # distância do Sol à Lua
  29. rlt = np.zeros(nt) # distância da Lua à Terra
  30.  
  31. xl = np.zeros(nt) # Posição horizontal da Lua
  32. yl = np.zeros(nt) # Posição vertical da Lua
  33. vxl = np.zeros(nt) # Velocidade horizontal da Lua
  34. vyl = np.zeros(nt) # Velocidade vertical da Lua
  35. axl = np.zeros(nt) # Aceleração horizontal da Lua
  36. ayl = np.zeros(nt) # Aceleração vertical da Lua
  37.  
  38. xlt = np.zeros(nt) # Posição horizontal da Lua em relação à Terra
  39. ylt = np.zeros(nt) # Posição vertical da Lua em relação à Terra
  40.  
  41. #Condições iniciais -------------------
  42. t[0] = 0
  43.  
  44. xt[0] = 147098290 #Km => periélio
  45. yt[0] = 0
  46.  
  47. xl[0] = xt[0] + 363104 #Km (rt + rlt)
  48. yl[0] = 0
  49.  
  50. xlt[0] = 363104 #Km
  51. ylt[0] = 0
  52.  
  53. vxt[0] = 0
  54. vyt[0] = 30.2787 #Km/s
  55. vyl[0] = vyt[0] + 1.10495 #31,38365 #Km/s
  56.  
  57.  
  58. #calculando distâncias em t=0
  59. rt[0] = ( xt[0]**2 + yt[0]**2 )**0.5
  60. rl[0] = ( xl[0]**2 + yl[0]**2 )**0.5
  61. rlt[0] = ( (xt[0]-xl[0])**2 + (yt[0]-yl[0])**2 )**0.5
  62.  
  63. #calculando acelerações em t=0
  64. axt[0] = -g*( (ms*xt[0]/rt[0]**3) + ml*(xt[0]-xl[0])/rlt[0]**3 )
  65. axl[0] = -g*( (ms*xl[0]/rl[0]**3) + mt*(xl[0]-xt[0])/rlt[0]**3 )
  66. ayt[0] = 0
  67. ayl[0] = 0
  68.  
  69. #Fórmulas para a evolução temporal
  70. for it in range (1,nt):
  71. t[it] = it*dt
  72.  
  73. if it==1:
  74. #calculando velocidades
  75. vxt[1] = vxt[0] + (0.5*dt*axt[0])
  76. vyt[1] = vyt[0] + (0.5*dt*ayt[0])
  77.  
  78. vxl[1] = vxl[0] + (0.5*dt*axl[0])
  79. vyl[1] = vyl[0] + (0.5*dt*ayl[0])
  80. else:
  81. #calculando velocidades
  82. vxt[it] = vxt[it-1] + (dt*axt[it-1])
  83. vyt[it] = vyt[it-1] + (dt*ayt[it-1])
  84.  
  85. vxl[it] = vxl[it-1] + (dt*axl[it-1])
  86. vyl[it] = vyl[it-1] + (dt*ayl[it-1])
  87.  
  88. #calculando posição (x,y)
  89. xt[it] = xt[it-1] + (vxt[it] * dt)
  90. xl[it] = xl[it-1] + (vxl[it] * dt)
  91. yt[it] = yt[it-1] + (vyt[it] * dt)
  92. yl[it] = yl[it-1] + (vyl[it] * dt)
  93.  
  94. xlt[it] = xl[it] - xt[it]
  95. ylt[it] = yl[it] - yt[it]
  96.  
  97. #calculando distâncias
  98. rt[it] = ( xt[it]**2 + yt[it]**2 )**0.5
  99. rl[it] = ( xl[it]**2 + yl[it]**2 )**0.5
  100. rlt[it] = ( (xt[it]-xl[it])**2 + (yt[it]-yl[it])**2 )**0.5
  101.  
  102. #calculando aceleração
  103. axt[it] = -g*( (ms*xt[it]/rt[it]**3) + ml*(xt[it]-xl[it])/rlt[it]**3 )
  104. axl[it] = -g*( (ms*xl[it]/rl[it]**3) + mt*(xl[it]-xt[it])/rlt[it]**3 )
  105.  
  106. ayt[it] = -g*( (ms*yt[it]/rt[it]**3) + ml*(yt[it]-yl[it])/rlt[it]**3 )
  107. ayl[it] = -g*( (ms*yl[it]/rl[it]**3) + mt*(yl[it]-yt[it])/rlt[it]**3 )
  108.  
  109. #---------------
  110. print('afélio : ', round(np.max(rt),0))
  111. print('periélio: ', round(np.min(rt),0))
  112. print('apogeu : ', round(np.max(rlt),0))
  113. print('perigeu : ', round(np.min(rlt),0))
  114. print()
  115.  
  116. #determinando período da Lua => 2 * tempo para ylt tornar-se negativo
  117. for it in range (1,nt):
  118. if( ylt[it] < 0 ):
  119. print('Período da Lua: ', round(2*it*dt /(24*60*60),2))
  120. break
  121.  
  122. #determinando período da Terra => 2 * tempo para yt tornar-se negativo
  123. for it in range (1,nt):
  124. if( yt[it] < 0 ):
  125. print('Período da Terra: ', round(2*it*dt /(24*60*60),2))
  126. break
  127. print()
  128.  
  129. # Plotando os Gráficos
  130.  
  131. # colocando um estilo para uso
  132. plt.style.use('fivethirtyeight')
  133.  
  134. # criando uma figura
  135. fig = plt.figure()
  136.  
  137. # definindo subplots e suas posições na figura
  138. plt1 = fig.add_subplot(121)
  139.  
  140. plt1.set_title('$Terra/Lua - Sol$')
  141. plt1.set_xlabel('x(km)')
  142. plt1.set_ylabel('y(km)')
  143.  
  144. for i in range(0, nt, 20):
  145. # plotting points on each subplot
  146. plt1.scatter(0., 0., color='r', s=40) #sol = vermelho
  147. plt1.scatter(xt[i], yt[i], color='b', s=3) #terra = azul
  148. plt1.scatter(xl[i], yl[i], color='g', s=3) #lua = verde
  149.  
  150. # função para mostrar a plotagem
  151. plt.show()
  152.  
  153. print()
  154.  
  155. # colocando um estilo para uso
  156. pltx.style.use('fivethirtyeight')
  157.  
  158. # criando uma figura
  159. fig = pltx.figure()
  160.  
  161. # definindo subplots e suas posições na figura
  162. plt2 = fig.add_subplot(121)
  163.  
  164. plt2.set_title('$Lua - Terra$')
  165. plt2.set_xlabel('xlt(km)')
  166. plt2.set_ylabel('ylt(km)' )
  167.  
  168. for i in range(0, nt, 500):
  169. # plotting points on each subplot
  170. plt2.scatter(0., 0., color='b', s=40) #terra = azul
  171. plt2.scatter(xlt[i], ylt[i], color='g', s=3) #lua = verde
  172.  
  173. # função para mostrar a plotagem
  174. pltx.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement