% Example 9-7: Flight of a model rocket m=0.05; g=9.81; tEngine=0.15; Force=16; vChute=-20; Dt=0.01; clear t v h % n counts the time steps of Dt n=1; % Initialize the time, velocity, and altitude variables t(n)=0; v(n)=0; h(n)=0; % Segment 1: climbing under power a1 = (Force-m*g)/m; % Compute t, v, h at each time step while t(n) < tEngine n = n+1; t(n) = t(n-1) + Dt; v(n) = a1*t(n); h(n) = 0.5*a1*t(n)^2; end % Store variables at the end of segment 1 v1=v(n); h1=h(n); t1=t(n); % Segment 2: no power % Compute t, v, h at each time step while v(n) >= vChute n = n+1; t(n) = t(n-1) + Dt; v(n) = v1-g*(t(n)-t1); h(n) = h1 + v1*(t(n)-t1) - 0.5*g*(t(n)-t1)^2; end % Store variables at the end of segment 2 v2=v(n); h2=h(n); t2=t(n); % Segment 3: with parachute % Compute t, v, h at each time step while h(n) > 0 n = n+1; t(n) = t(n-1) + Dt; v(n) = vChute; h(n) = h2 + vChute*(t(n)-t2); end subplot(1,2,1) plot(t, h, t2, h2, 'o') xlabel('Time(s)') ylabel('Height (m)') subplot(1,2,2) plot(t, v, t2, v2, 'o') xlabel('Time(s)') ylabel('Velocity (m/s)')