Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ive written the following code in MatLab but I need help creating a graph that accurately depicts whats occuring. I am using potential energy and

Ive written the following code in MatLab but I need help creating a graph that accurately depicts whats occuring. I am using potential energy and spring constants to calculate the effects of celestial bodies orbiting. please let me know if you notice any mistakes in my code. I would like the graph to be a accurate depiction of the Orbit of the Earth moon and sun based upon the formulas in my code. % Define masses
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 spring constants
k12=0.1; % Spring constant between particle 1 and particle 2
k23=0.5; % Spring constant between particle 2 and particle 3
% Define initial positions
x1=0; y1=0; % Initial position of particle 1(Sun)
x2=149.6e9; y2=0; % Initial position of particle 2(Earth)
x3= x2+384.4e6; y3=0; % Initial position of particle 3(Moon)
% Define initial velocities
vx1=0; vy1=0; % Initial velocity of particle 1(Sun)
vx2=0; vy2=29.783e3; % Initial velocity of particle 2(Earth)
vx3=0; vy3=29.783e3+1.022e3; % Initial 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
x1_array = zeros(1, n); y1_array = zeros(1, n);
x2_array = zeros(1, n); y2_array = zeros(1, n);
x3_array = zeros(1, n); y3_array = zeros(1, n);
% 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);
r23= sqrt((x3- x2)^2+(y3- y2)^2);
% Calculate forces using the spring potential
F12=-k12*(r12-1); % Assuming equilibrium distance r0=1 for particle 1-2
F23=-k23*(r23-1); % Assuming equilibrium distance r0=1 for particle 2-3
% Calculate accelerations
ax1= F12*(x2- x1)/ r12/ m1;
ay1= F12*(y2- y1)/ r12/ m1;
ax2=(F12*(x1- x2)/ r12+ F23*(x3- x2)/ r23)/ m2;
ay2=(F12*(y1- y2)/ r12+ F23*(y3- y2)/ r23)/ m2;
ax3= F23*(x2- x3)/ r23/ m3;
ay3= F23*(y2- y3)/ r23/ m3;
% 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_2

Step: 3

blur-text-image_3

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

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

8. Do the organizations fringe benefits reflect diversity?

Answered: 1 week ago

Question

7. Do the organizations social activities reflect diversity?

Answered: 1 week ago