Advertisement
Guest User

Untitled

a guest
May 27th, 2019
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. def fx(x):
  2.     r = p / (1 + e*np.cos(x))
  3.     return r
  4.  
  5. import numpy as np
  6. import matplotlib.pyplot as plt
  7.  
  8. pi, twopi = np.pi, 2*np.pi
  9. degs, rads = 180/pi, pi/180
  10.  
  11. # Setup
  12. L = 9.11E+38     #L = angular momentum
  13. m = 3.28E+23     #m = mass of mercury
  14. M = 1.99E+30     #M = mass of sun
  15. a = 5.8E+10      #a = semi-major axis
  16. G = 6.674E-11    #G = Gravitationl constant
  17. k = G*M*m
  18. E = -k/(2*a)     #E = energy
  19. #E = 0
  20. p = L**2 / (m*k)  
  21. c = 1 + (2*E*L**2) / (m*k**2)
  22.  
  23. e = np.sqrt(c)   #e = eccentricity
  24. print(e,c)
  25.  
  26. # Initialize
  27. phi    = np.linspace(0, twopi, 100)
  28.  
  29. radius = fx(phi)
  30. theta  = degs * phi
  31.  
  32. x, y = radius * np.cos(phi), radius * np.sin(phi)
  33.  
  34. print('r =',radius)
  35. print('x =',x)
  36. print('y =',y)
  37. plt.plot(x,y)
  38. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement