a = 6793.137;
mu = 398600.5;
n = sqrt(mu/a^3);
t0 = 0;
tf = 5400;
initial_condition = [x(0) y(0) z(0)]
[T,position] = ode45(@(t,position)Clohessy_Wiltshire(t,x,y,z),[t0 tf],initial_condition);
figure(1), hold on, plot(T,position(:,1),'b'), plot(T,position(:,2), 'r'), plot(T,position(:,3), 'g')
title('Position(X,Y,Z) vs. Time')
ylabel('Position(X,Y,Z)(km)')
xlabel('Time(s)')
figure(2), hold on, plot(T,position(:,4),'b'), plot(T,position(:,5), 'r'), plot(T,position(:,6), 'g')
title('Velocity(dX,dY,dZ) vs. Time')
ylabel('Velocity(dX,dY,dZ)')
xlabel('Time(s)')
function position = Clohessy_Wiltshire(~,x,y,z,dx,dy,dz,n)
x(0) = -0.066538073651029;
dx(0) = -0.000052436200437;
dx(2) = 2*n*dy;
y(0) = 0.186268907590665;
dy(0) = 0.000154811363681;
dy(2) = -2*n*dx;
z(0) = 0.000003725378152;
dz(0) = 0.000210975508077;
dz(2) = -n^2*z;
end
4 Comments
madhan ravi (view profile)
Direct link to this comment:
https://www.mathworks.com/matlabcentral/answers/434127-how-to-solve-system-of-2nd-order-differential-equations-using-ode45#comment_646891
Star Strider (view profile)
Direct link to this comment:
https://www.mathworks.com/matlabcentral/answers/434127-how-to-solve-system-of-2nd-order-differential-equations-using-ode45#comment_646892
Ryan Bowman (view profile)
Direct link to this comment:
https://www.mathworks.com/matlabcentral/answers/434127-how-to-solve-system-of-2nd-order-differential-equations-using-ode45#comment_646893
Ryan Bowman (view profile)
Direct link to this comment:
https://www.mathworks.com/matlabcentral/answers/434127-how-to-solve-system-of-2nd-order-differential-equations-using-ode45#comment_646898
Sign in to comment.