Question
Im trying to plot the Orbit of the earth around the sun using the verlet method in Python However i cant seem to plot anything
Im trying to plot the Orbit of the earth around the sun using the verlet method in Python However i cant seem to plot anything thing in SI units If i were to show the masses of the bodies in solar masses the code works, just not in SI
Where am i going wrong? Here is my code so far
mi=1.98e30 #This is the mass of the Sun in kg xi=0 # postion of the sun x direction yi=0 # position of the sun y direction xj=1.5e11 yj=0 #POSITION EARTH IN Y DIRECTION mj=5.97e24 #this is the mass of the Earth in solar masses G=6.637e-11 #4*np.pi**2 #This is the Universal Gravitational Constant 6.637e-11[m^3kg^-1s^-2] vy=29747 #earths initial velocity
def FGRAV(mi,mj,r): r=np.sqrt((xi-xj)**2+(yi-yj)**2) return -G*mi*mj/r**3 def Earthorbit(r0=np.array([1.5e11, 0]), v0=np.array([0, 29747]), mass=mi, dt=0.001, t_max=1): dim = len(r0) assert len(v0) == dim nsteps = int(t_max/dt)
r = np.zeros((nsteps, dim)) v = np.zeros_like(r)
r[0, :] = r0 v[0, :] = v0
#verlet method of integration # start force evaluation for first step Ft = FGRAV(r[0], mj,mi) for k in range(nsteps-1): vhalf = v[k] + 0.5*dt * Ft/mass r[k+1] = r[k] + dt * vhalf Ftdt = FGRAV(r[k+1], mj,mi) v[k+1] = vhalf + 0.5*dt * Ftdt/mass #acceleration of body # new force becomes old force Ft = Ftdt return r, v
r, v =Earthorbit(dt=0.01, t_max=10)
rx, ry = r.T ax = plt.subplot(1,1,1) plt.xlim(-2e15,2e15) plt.ylim(-2e15,2e15) plt.set_aspect(1) ax.plot(rx,ry,color='b', alpha=1.0, lw=1.5,)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started