t(1) = 0; %Time, seconds
T(1) = 0; %Thrust, Newtons
m = 85/1000; % mass, grams
h(1) = 0.2; %Height, meters
A_rocket = 1.2141; %Drag Area, meters^2
c_d = 0.06; %Coefficient of Drag
g = 9.81; %Gravity, meters/second^2
p = 1.225; %Air Density, kilograms/meter^3
v(1) = 0; %Velocity, meters/second
a(1) = 0; %Acceleration, meters/second^2
W = 0.324; %Weight, Newtons
%%
i = 1; %Loop Term
h_check = h(1); %Height Check
t_step = 0.01; %Time Step Intervals
while h_check >= -0.5 %Thrust Function
if t(i) <= 0.22 T(i) = 45.45*(t(i)); elseif t(i) <= 0.27 T(i) = -140*(t(i))+3; elseif t(i) <= 0.67 T(i) = -2.5*(t(i))+3; elseif t(i) <= 0.72 T(i) = -40*(t(i))+2; else T(i) = 0; break end a(i+1)= - m * g + T(i) - c_d * ((p * v(i).^2)/2) * 0.2 / m v(i + 1) = v(i) + a(i) * t_step h(i + 1) = h(i) + v(i) * t_step t(i+1) = t(i)+t_step; i = i + 1 endt(end) = [];h(end) = [];figureplot(t,T)title('Time Vs. Thrust')xlabel('Time')ylabel('Thrust')figureplot(t,a)title('Time Vs. Acceleration')xlabel('Time')ylabel('Acceleration')figure plot(t,v)title('Time Vs. Velocity')xlabel('Time')ylabel('Velocity')figureplot(t,h)title('Time Vs. Height')xlabel('Time')ylabel('Height')
MATLAB: Keep on getting ‘Error using plot, Vectors must be the same length’. How to plot it correctly
plotplottingwhile loop
Best Answer