Answered step by step
Verified Expert Solution
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
me; Mass of particle Sun
me; Mass of particle Earth
me; Mass of particle Moon
Define spring constants
k; Spring constant between particle and particle
k; Spring constant between particle and particle
Define initial positions
x; y; Initial position of particle Sun
xe; y; Initial position of particle Earth
x xe; y; Initial position of particle Moon
Define initial velocities
vx; vy; Initial velocity of particle Sun
vx; vye; Initial velocity of particle Earth
vx; vyee; Initial velocity of particle Moon
Define time step and number of iterations
dt ; Time step
n ; Number of iterations year
Initialize arrays to store positions
xarray zeros n; yarray zeros n;
xarray zeros n; yarray zeros n;
xarray zeros n; yarray zeros n;
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;
Calculate forces using the spring potential
Fkr; Assuming equilibrium distance r for particle
Fkr; Assuming equilibrium distance r for particle
Calculate accelerations
ax Fx x r m;
ay Fy y r m;
axFx x r Fx x r m;
ayFy y r Fy y r m;
ax Fx x r m;
ay Fy y r m;
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