Code: Select all
clear,clc
% Inputs for Rocket mass and Initial Applied Force
m = input('Enter mass of Rocket in kilograms: ');
Fi = input('Enter intial Force in Newtons: ');
% Constants and intial Acceleration, AO
g = 9.8;
A0 = (Fi - m*g)/m;
% Time the Parachute opens
P = 20/g + 0.15*A0/g +0.15;
% Time the Rocket hits the Ground
G = (0.5*A0*(0.15)^2 + A0*0.15*(P-0.15) - 0.5*g*(P)^2 + 0.15*g*P - 0.01125*g)/20 + P;
% Time matrix
t = 0:0.001:G;
% Empty y and v for piecewise function
y = nan*ones(size(t));
v = nan*ones(size(t));
% y(t) the height of the Rocket versus Time, t.
y(0<t & t<=0.15) = 0.5*A0.*t(0<t & t<=0.15).^2;
y(0.15<t & t<=P) = 0.5*A0*(0.15)^2 + A0*0.15.*(t(0.15<t & t<=P)-0.15) - 0.5*g.*t(0.15<t & t<=P).^2 + 0.15*g.*t(0.15<t & t<=P) - 0.01125*g;
y(P<t & t<=G) = 0.5*A0*(0.15)^2 + A0*0.15*(P-0.15) - 0.5*g*(P)^2 + 0.15*g*P - 0.01125*g - 20.*(t(P<t & t<=G)-P);
% y'(t) = v(t)
v(0<t & t<=0.15) = A0.*t(0<t & t<=0.15);
v(0.15<t & t<=P) = A0*0.15 - g.*t(0.15<t & t<=P) + 0.15*g;
v(P<t & t<=G) = -20 + 0.*t(P<t & t<=G);
% Plotting the results
subplot(2,1,1),plot(t,y);
title('y (height) versus t')
xlabel('time')
ylabel('y (height)')
subplot(2,1,2),plot(t,v);
title('v versus t')
xlabel('time')
ylabel('velocity')
shg