Modelling simple orbits using Newton's law of gravitation
3 views (last 30 days)
Show older comments
Hey guys,
I've been trying to create a program that shows the orbit of a satellite about a large body of mass in a Cartesian coordinate system using Newton's law of gravitation but I seem to be having a little trouble. Here is to code for my program so far.
function orbit
%Initial time
t0=0;
%Final time
tf=300;
%Initial x-position
x0=-1000;
%Initial y-position
y0=0;
%Initial velocity
v0=10;
%Initial angle
a0=45;
%Initial x-velocity
vx0=v0*cosd(a0);
%Initial y-velocity
vy0=v0*sind(a0);
%Mass of large object at (0,0)
M=7e18;
%Gravitational constant
G=6.672e-11;
%Initial condition vector
s0=[x0 y0 vx0 vy0];
%ODE solver
[t,s]=ode45(@f,[t0 tf],s0)
%Plotting calculations
x=s(:,1);
y=s(:,2);
vx=s(:,3);
vy=s(:,4);
subplot(3,1,1);
plot(t,vx);
xlabel('t');
ylabel('vx');
grid on
subplot(3,1,2);
plot(t,vy);
xlabel('t');
ylabel('vy');
grid on
subplot(3,1,3);
plot(x,y);
xlabel('x');
ylabel('y');
grid on
function dfdt=f(t,s)
x=s(1);
y=s(2);
vx=s(3);
vy=s(4);
r=sqrt(x^2+y^2);
dxdt=vx;
dydt=vy;
%x component of gravitational acceleration
d2xdt2=-((G*M)/r^2)*cosd(a0);
%y component of gravitational acceleration
d2ydt2=-((G*M)/r^2)*sind(a0);
dfdt=[dxdt;dydt;d2xdt2;d2ydt2];
end
end
I had hoped to get something that looks like this: http://imageshack.us/photo/my-images/811/orbity.jpg/ but instead my orbit looks like this: http://imageshack.us/photo/my-images/23/myorbit.jpg/. Any help would be appreciated, thanks guys.
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!