Answered step by step
Verified Expert Solution
Link Copied!

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 Sun-m1,Earth-m2, and moon-m3). 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 =6.674e-11; % Gravitational constant
% Define masses of particles
m1=1.9891e30; % Mass of particle 1(Sun)
m2=5.97219e24; % Mass of particle 2(Earth)
m3=7.34767e22; % Mass of particle 3(Moon)
% Define initial positions of particles
x1=0; % Initial x-position of particle 1(Sun)
y1=0; % Initial y-position of particle 1(Sun)
x2=149.6e9; % Initial x-position of particle 2(Earth)
y2=0; % Initial y-position of particle 2(Earth)
x3= x2+384.4e6; % Initial x-position of particle 3(Moon)
y3=0; % Initial y-position of particle 3(Moon)
% Define initial velocities of particles
vx1=0; % Initial x-velocity of particle 1(Sun)
vy1=0; % Initial y-velocity of particle 1(Sun)
vx2=0; % Initial x-velocity of particle 2(Earth)
vy2=29.783e3; % Initial y-velocity of particle 2(Earth)
vx3=0; % Initial x-velocity of particle 3(Moon)
vy3=29.783e3+1.022e3; % Initial y-velocity of particle 3(Moon)
% Define time step and number of iterations
dt =3600; % Time step
n =365*24; % Number of iterations (1 year)
% Initialize arrays to store positions and velocities
x1_array = zeros(1, n); % Array to store x-positions of particle 1
y1_array = zeros(1, n); % Array to store y-positions of particle 1
x2_array = zeros(1, n); % Array to store x-positions of particle 2
y2_array = zeros(1, n); % Array to store y-positions of particle 2
x3_array = zeros(1, n); % Array to store x-positions of particle 3
y3_array = zeros(1, n); % Array to store y-positions of particle 3
% Store initial positions
x1_array(1)= x1;
y1_array(1)= y1;
x2_array(1)= x2;
y2_array(1)= y2;
x3_array(1)= x3;
y3_array(1)= y3;
% Perform the iterations and calculate positions
for i =2:n
% Calculate distances between particles
r12= sqrt((x2- x1)^2+(y2- y1)^2);
r13= sqrt((x3- x1)^2+(y3- y1)^2);
r23= sqrt((x3- x2)^2+(y3- y2)^2);
% Calculate accelerations
ax1= G * m2*(x2- x1)/ r12^3+ G * m3*(x3- x1)/ r13^3;
ay1= G * m2*(y2- y1)/ r12^3+ G * m3*(y3- y1)/ r13^3;
ax2= G * m1*(x1- x2)/ r12^3+ G * m3*(x3- x2)/ r23^3;
ay2= G * m1*(y1- y2)/ r12^3+ G * m3*(y3- y2)/ r23^3;
ax3= G * m1*(x1- x3)/ r13^3+ G * m2*(x2- x3)/ r23^3;
ay3= G * m1*(y1- y3)/ r13^3+ G * m2*(y2- y3)/ r23^3;
% Update velocities
vx1= vx1+ ax1* dt;
vy1= vy1+ ay1* dt;
vx2= vx2+ ax2* dt;
vy2= vy2+ ay2* dt;
vx3= vx3+ ax3* dt;
vy3= vy3+ ay3* dt;
% Update positions
x1= x1+ vx1* dt;
y1= y1+ vy1* dt;
x2= x2+ vx2* dt;
y2= y2+ vy2* dt;
x3= x3+ vx3* dt;
y3= y3+ vy3* dt;
% Store positions in arrays
x1_array(i)= x1;
y1_array(i)= y1;
x2_array(i)= x2;
y2_array(i)= y2;
x3_array(i)= x3;
y3_array(i)= y3;
end

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

Recommended Textbook for

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

More Books

Students also viewed these Databases questions

Question

Complexity of linear search is O ( n ) . Your answer: True False

Answered: 1 week ago

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago