Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are 5 functions and one integrate function. Some of the force functions are working and others are not. The notes indicate what is and

There are 5 functions and one integrate function. Some of the force functions are working and others are not. The notes indicate what is and is not working and the integrate code block is empty and returns 0.

# add necessary importsimport numpy as npimport matplotlib.pyplot as plt# Given 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=float, mj=float): #Force Functionrij = ri-rj;length = np.sqrt(np.dot(rij,rij))direction_norm = rij / (rij**2).sum()**0.5return (-G*mi*mj/(length**2))*direction_normdef F_ES(rE): ## Gravitional force on earth by sunreturn F_gravity(r0["sun"],rE,mass["earth"],mass["sun"])def integrate_earth(tmax,dt=1e-3): ## the functionsteps = 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*dtv-=m_inv*F_ES(r.copy())*dtr_values.append(r.copy())return r_values#FORCE FUNCTION 1#This is NOT correctdef F_EM(rE, rM):rE = r0["earth"]rM = mass["moon"]returnnp.array( F_gravity(rM, rE ,mass["moon"],mass["earth"]) )#FORCE FUNCTION 2#This is correctdef F_ME(rE, rM):return np.array( F_gravity(rM, rE ,mass["moon"],mass["earth"]) )#FORCE FUNCTION 3#This is correctdef F_MS(rM):return np.array( F_gravity(rM, r0["sun"] ,mass["moon"],mass["sun"]) )#FORCE FUNCTION 4#This is NOT correctdef F_E(rE, rM):return np.array( F_gravity(rM, rE ,mass["moon"],mass["earth"]) )#FORCE FUNCTION 5#This is NOT correctdef F_M(rE, rM):return np.array( F_gravity(rE, rM ,mass["earth"],mass["moon"]) )def integrate_EM(tmax, dt=1e-3): # Start of code block but not completedreturn 0if __name__ == "__main__":# create the trajectory# PLOT FUNCTIONS'''This is dummy code being worked on but close to what is neededpositions = integrate_EM(1)#stand in set up code for plottingarray =np.array(positions)#stand in set up code for plottingpositions2 = integrate_EM(2)#stand in set up code for plottingarray2 =np.array(positions2)#stand in set up code for plottingplt.plot(0,0, label = 'Earth')#stand in set up code for plottingplt.grid(True)#stand in set up code for plotting#plt.xlabel("x (AU)")#stand in set up code for plotting#plt.ylabel("y (AU)")#stand in set up code for plotting#plt.legend()#stand in set up code for plotting#plt.show()#stand in set up code for plottingplt.plot(0,0, label = 'Moon')#stand in set up code for plottingplt.grid(True)#stand in set up code for plottingplt.xlabel("x (AU)")#stand in set up code for plottingplt.ylabel("y (AU)")#stand in set up code for plottingplt.legend()#stand in set up code for plottingplt.show()#stand in set up code for plottingplt.savefig("orbit_earth_moon.png")#stand in set up code for plotting'''

image text in transcribedimage text in transcribedimage text in transcribed
\f\f\f

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions

Question

how technology can empower or disrupt your organization.

Answered: 1 week ago