Can I please get some help with problem 5? The code below is the code that needs
ID: 3851777 • Letter: C
Question
Can I please get some help with problem 5? The code below is the code that needs to be modified.
clc
clear
disp('ENGR15100 Prelab 9')
disp('Your name here')
disp(' ')
%Run script file for rocket calculations
rocket2h2
%rocket2h2.m
%
clc
b=input('Enter desired burn time ');
disp(' ')
h_des=input('Enter desired height ');
disp(' ')
dt=.1;
m=10;
f=2000;
g=32.2;
%calculate constants
v_b=(f/m-g)*b;
h_b=0.5*(f/m-g)*b^2;
h_p=h_b+v_b^2/(2*g);
t_p=b+v_b/g;
figure(2)
%Begin calculating flight
h=0;
k=0;
while h>=0
t=k*dt;
k=k+1;
if t<=b
h=0.5*(f/m-g)*t^2;
v=(f/m-g)*t;
else
%calc rest of unpowered ascent
h=h_b-.5*g*(t-b)^2+v_b*(t-b);
v=v_b-g*(t-b);
end
plot(t,h,'b.')
hold on
end
%disp('Time to desired height is:')
disp('Time to hit the ground is:')
disp(t)
disp(' ')
hold off
%Next based on burn time and desired altitude the code will determine time to reach
%altitude if possible check if peak height greater than altitude desired.
if h_p>h_des %do-able!
h=0;
k=0;
t=0;
while h<h_des
t=k*dt;
k=k+1;
if t<=b
h=0.5*(f/m-g)*t^2;
v=(f/m-g)*t;
else
%calc rest of unpowered ascent
h=h_b-.5*g*(t-b)^2+v_b*(t-b);
v=v_b-g*(t-b);
end
end
disp('Time to desired height is:')
disp(t)
else
disp('Rocket will not achieve desired altitude of:')
disp(h_des)
end
Explanation / Answer
% Model Parameters burnrate = 50; % kg/s fuel = 4000; % kg t = fuel / burnrate; % seconds a_thrust = + 20; % m/s^2 a_gravity = -9.8; % m/s^2 y_0 = 0; % m v_0 = 0; %m/s % Simulate each second: altitude = y_0; velocity = v_0; acceleration = 0; time = 0; % Simulate until rocket is below ground level while altitude >= 0 time(end + 1) = time(end) + 1; % Change model behavior based on fuel if fuel > 0 deltaFuel = burnrate; accel = a_thrust; else deltaFuel = 0; accel = a_gravity; end % Build vectors for each parameter at each timestep fuel = fuel - burnrate; acceleration(end + 1,1) = accel; velocity(end + 1,1) = velocity(end) + accel; altitude(end + 1,1) = altitude(end) + velocity(end); end % Use logical indexing to select the data corresponding to a positive % vertical velocity % Some benefits of this approach are that you can do additional % math on your results. For example, you could find the points with % positive acceleration as follows (if you didn't already have an % acceleration vector) posAccelIndex = diff(velocity)>0; % NOTE: this vector is 1 line shorter than the model! posAccelIndex = [true; posAccelIndex]; % Include the initial condition % Since you do have that parameter, you can use simple logical % indexing: posAccelIndex = acceleration >= 0; % Print some output - use the vectors you built in the model disp(sprintf('Altitude reached: %f meters', max(altitude))); disp(sprintf('Velocity at impact: %f m/s', velocity(end))); % Plot your results using logical indexing to color code and set the legend figure; subplot(1,2,1) hold on; plot(time(posAccelIndex), velocity(posAccelIndex), 'r', 'displayname', 'Powered'); plot(time(~posAccelIndex), velocity(~posAccelIndex), 'b', 'displayname', 'Freefall'); title('Vehicle Velocity (in m/s)') legend('show') subplot(1,2,2) hold on; plot(time(posAccelIndex), altitude(posAccelIndex), 'r', 'displayname', 'Powered'); plot(time(~posAccelIndex), altitude(~posAccelIndex), 'b', 'displayname', 'Freefall'); title('Vehicle Altitude (in m)') legend('show')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.