¿How can y create an orbit simulator using euler's method? Please Help!! Would really appreciate it
2 views (last 30 days)
Show older comments
Hello I´am tasked with making a program that can simulate a planets orbit by using the euler's method, however i'm very new to programing and i'm having a lot of trouble creating a code.
heres the exact assignment:
ASTRONOMICAL MOTION OF SOLID BODIES Astronomical motion is governed by Newton’s laws of motion and gravitation – you are to implement a solver that can predict trajectories based on the masses and initial positions & velocities. In a simple two body system the solutions are given by Kepler’s laws which can be used to verify numerical solvers. Once three or more bodies are involved behavior becomes much more interesting, e.g. Trojan satellites of Jupiter. The formation of these systems is quite complex, however by starting the solver with known solutions we can check that the orbits are stable, and also by perturbing the orbits and watching them settle back. How far can the (e.g. satellite) positions be perturbed? How does this depend on mass?
and here is what i have so far:
clear;
% The initial values are written below %
dt=0.5; %12 hours
t=[0:dt:365]; %one year, earth's period
maxt=length(t);
M= 1.989*10^30; % mass of larger the body
m= 5.972*10^24; % mass of the smaller body
x= 147.1; % Intitial position in x axes of smaller objet measuring from lager object
y= 0; %Intitial position in y axes of smaller objet measuring from lager object
x(1)=x;
y(1)=x;
vx= 0;
vy= 30300;
vx(1)=vx;
vy(1)=vy;
G= 6.67408*10^(-11);% Value of the Gravitational Constant
ax=((-G*M)*x)/(((x^2)+(y^2))^(3/2));
ay=((-G*M)*y)/(((x^2)+(y^2))^(3/2));
ax(1)=ax;
ay(1)=ay;
for i=1:maxt-1
vx(i+1)= vx(i)+(ax(i)*t(i));
vy(i+1)= vy(i)+(ay(i)*t(i));
x(i+1)= x(i)+(vx(i+1)*t(i));
y(i+1)= y(i)+(vy(i+1)*t(i));
ax(i+1)= ((-G*M)*x(i+1))/(((x(i+1)^2)+(y(i+1)^2))^(3/2));
ay(i+1)= ((-G*M)*y(i+1))/(((x(i+1)^2)+(y(i+1)^2))^(3/2));
end
plot(dt,y)
0 Comments
Answers (0)
See Also
Categories
Find more on Gravitation, Cosmology & Astrophysics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!