Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Ive written the following code in MatLab I used verlet method to calculate the orbit of the Sun - m 1 , Earth - m
Ive written the following code in MatLab I used verlet method to calculate the orbit of the SunmEarthm and moonm I need help creating a graph that accuratly depicts the orbit of these celestial bodies. I would like the to see the Earth orbiting the sun along with the path it will follow and the moon orbiting the Earth and the path that will follow. I would also like this graph to update the position of the earth and moon as time passes so it playes out like you're watching the earth rotate the sun and the moon rotate around the earth. clear all
Define constants
G e; Gravitational constant
Define masses of particles
me; Mass of particle Sun
me; Mass of particle Earth
me; Mass of particle Moon
Define initial positions of particles
x; Initial xposition of particle Sun
y; Initial yposition of particle Sun
xe; Initial xposition of particle Earth
y; Initial yposition of particle Earth
x xe; Initial xposition of particle Moon
y; Initial yposition of particle Moon
Define initial velocities of particles
vx; Initial xvelocity of particle Sun
vy; Initial yvelocity of particle Sun
vx; Initial xvelocity of particle Earth
vye; Initial yvelocity of particle Earth
vx; Initial xvelocity of particle Moon
vyee; Initial yvelocity of particle Moon
Define time step and number of iterations
dt ; Time step
n ; Number of iterations year
Initialize arrays to store positions and velocities
xarray zeros n; Array to store xpositions of particle
yarray zeros n; Array to store ypositions of particle
xarray zeros n; Array to store xpositions of particle
yarray zeros n; Array to store ypositions of particle
xarray zeros n; Array to store xpositions of particle
yarray zeros n; Array to store ypositions of particle
Store initial positions
xarray x;
yarray y;
xarray x;
yarray y;
xarray x;
yarray y;
Perform the iterations and calculate positions
for i :n
Calculate distances between particles
r sqrtx xy y;
r sqrtx xy y;
r sqrtx xy y;
Calculate accelerations
ax G mx x r G mx x r;
ay G my y r G my y r;
ax G mx x r G mx x r;
ay G my y r G my y r;
ax G mx x r G mx x r;
ay G my y r G my y r;
Update velocities
vx vx ax dt;
vy vy ay dt;
vx vx ax dt;
vy vy ay dt;
vx vx ax dt;
vy vy ay dt;
Update positions
x x vx dt;
y y vy dt;
x x vx dt;
y y vy dt;
x x vx dt;
y y vy dt;
Store positions in arrays
xarrayi x;
yarrayi y;
xarrayi x;
yarrayi y;
xarrayi x;
yarrayi y;
end
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