- #1
saeede-
- 9
- 0
hi guys, I'm trying to write a program in MATLAB to solve and plot equation of motion of 2 body problem but it errors as i don't know what it says!
do you know how to help me? please!
The main equation is r(double dot)=-(mu)*r(hat)/r^3
The code that i wrote is:
<Moderator's note: code tags added. Please use them.>
do you know how to help me? please!
The main equation is r(double dot)=-(mu)*r(hat)/r^3
The code that i wrote is:
Matlab:
clear all
close all
clc
R=6371e+3;
r0=3e+5;
p0=[R+r0;0;0;7000;0;0];
[t,p]=ode45(@sattelite,[0,3.15581e+07],p0);
xout=p(:,1);
yout=p(:,2);
zout=p(:,3);
plot3d(xout,yout,zout)
function dp=sattelite(t,p)
p=[x position;y position;z position;x velocity(vx);y velocity(vy);z velocity(vz)];
G=6.67e-11;
Me=5.972e+24;
m=50;
mu=(Me+m)*G;
R=6371e+3;
r0=3e+5;
r=sqrt(p(1)^2+p(2)^2+p(3)^2);
dp=zeros(6,1);
dp(1)=p(4);
dp(2)=p(5);
dp(3)=p(6);
dp(4)=-(mu/r^3)*p(1);
dp(5)=-(mu/r^3)*p(2);
dp(6)=-(mu/r^3)*p(3);
end
Last edited by a moderator: