This is my code. Im expecting to get 4 graphs but it only plots 2 at a time! how can i fix this?
Thank you
clear allclose allclcmu = 398600;minutes = 60; %Conversion from minutes to seconds
x0 = [10000; 0; 0];v0 = [0; -5.8; 0];Y0 = [x0; v0];t0 = 0;tf = 1440*minutes;options = odeset('RelTol', 1e-8, 'AbsTol', 1e-8) ;[t,Y] = ode45(@twobodyEOM, [t0 tf], Y0, options, mu);plotit(t, Y, minutes)x=Y(:,1);y=Y(:,2);plot(x,y);title('2D Trajectory')xlabel('x position, km')ylabel('y position, km')grid ongrid minorR = sqrt(Y(:,1).^2 + Y(:,2).^2 + Y(:,3).^2);V = sqrt(Y(:,4).^2 + Y(:,5).^2 + Y(:,6).^2);e=((V.^2)/2)-mu./R;plot(t,e)title('Specific Energy vs. Time')xlabel('Time')ylabel('Specific Energy')grid ongrid minor% ~~~~~~~~~~~~~~~~~~~~~~~~
function dYdt = twobodyEOM(t,Y,mu)rvec = Y(1:3);vvec = Y(4:6);r = sqrt(rvec(1)^2+rvec(2)^2+rvec(3)^2);rdotvec = vvec ;vdotvec = -mu/r^3*rvec ;dYdt = [rdotvec; vdotvec];end % ~~~~~~~~~~~~~~~~~~~~~~~~function dYdt = rates(t,Y,mu)x = Y(1);Dx = Y(2); % v
D2x = -mu/x^2; % vdot
dYdt = [Dx; D2x];end %rates
function plotit(t, Y, minutes)% ~~~~~~~~~~~~~
%...Position vs time:
subplot(2,1,1)plot(t/minutes,Y(:,1), '-ok')xlabel('time, minutes')ylabel('position, km')grid onaxis([-inf inf 5000 15000])%...Velocity versus time:
subplot(2,1,2)plot(t/minutes,Y(:,2), '-ok')xlabel('time, minutes')ylabel('velocity, km/s')grid onaxis([-inf inf -10 10]) end %plotit
Best Answer