Using your work from the previousproblems, you can now simulate thetrajectories of the interact… Show more… Show more is exerted by the Sun and the Earth.The force from the Moon on the Earthis Gm m .. FEM (t) = _+tMr… Show more… Show more Note that, for instance, rE (t + 1)means “the position of the Earthat time step t+1”. In … Show more… Show more Optional To make the plot prettier youcan do the tollowing (optional): Set theaspect ratio to equal with … Show more… Show <—- this is the code I have so far# add necessary importsimport numpy as npimport mathimport matplotlib.pyplot as plt# constantsG = 4*np.pi**2mass = { ‘sun’: 1.0, ‘earth’: 3.0034e-6, ‘moon’: 3.6923e-7}r0 = { ‘sun’: np.array([0,0,0]), ‘earth’: np.array([9.978977040419635E-01, 6.586825681892025E-02, -6.320430920521123E-06]), ‘moon’: np.array([9.956768547953816E-01, 6.676030485840675E-02, 1.641093070596718E-04]) }v0 = { ‘sun’: np.array([0,0,0]), ‘earth’: np.array([-4.70015711e-01, 6.25165839e+00, -3.40817831e-04]), ‘moon’: np.array([-0.55065949, 6.03534661, 0.01111456])}# functionsdef F_gravity(ri, rj, mi, mj):rij = ri-rjlength = np.sqrt(,rij))dirNorm = rij / (rij**2).sum()**0.5return (-G*mi*mj/(length**2))*dirNormprint(F_gravity(r0[‘moon’],r0[‘earth’],mass[‘moon’],mass[‘earth’]))def F_ES(rE):return -F_gravity(r0[“sun”],rE,mass[“earth”],mass[“sun”])def integrate_earth(tmax,dt=1e-3):steps = np.arange(0,tmax,dt)r_values=[]r=r0[“earth”].copy()v =v0[“earth”].copy()m_inv = 1/(mass[“earth”])r_values.append(r.copy())for t in steps: r +=v*dt v+=m_inv*F_ES(r.copy())*dt r_values.append(r.copy())return np.array(r_values)if __name__ == “__main__”:positions = integrate_earth(1)array =(positions)plt.plot(array[:,0],array[:,1])plt.xlabel(“x (AU)”)plt.ylabel(“y (AU)”)plt.savefig(“orbit_earth_only.png”) ScienceEngineering & TechnologyPython Programming CS/IS 112

Order your essay today and save 20% with the discount code ESSAYHELP