Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can I please get some help with problem 5? I have to use a function for the prob

ID: 3851809 • Letter: C

Question

Can I please get some help with problem 5? I have to use a function for the problem. The function and the code that needs to be modified is included below.

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

STEP 2: Using the functions created above solve again the problems of lab 9 step 1. You will be writing standalone script files for each problem so each should begin with clear and clc. Please use the usual file naming of firstname_lastname_lab9 step2_problem1.m etc., for each of the five problems Problem 1 i) Ask the user to enter the values of the empty rocket mass m, the engine force f, the engine burn time b, and the time step dt. Calculate the flight parameters of the rocket velocity at engine shut down v_b, altitude at engine shut down h _b, peak altitude h p, and the time of peak altitude t p. Use the same values you used in lab 8 for m,f,b and g- 32.2 Display (using fprintf) messages with values of the variables calculated above ii) Problem 2 i) Ask the user to enter the same parameters as above, and produce a plot of altitude h from the time of launch to ground impact i) Create the plot in figure 2, add x and y labels, title, and a grid Problem 3 i) Ask the user to enter the same parameters as in 1) and calculate the velocity v and altitude h of the rocket from the time of launch to ground impact. Use the same values as before. i) Create a two-row, one-column subplot in figure 3. Subplot one shows altitude h over time, while subplot two shows velocity v over time Problem 4 i) Add the additional input function get_h des to the list of input parameters and then determine the time at which h = 3000 on the way up. Use a FOR loop technique and the same rocket parameters as in 1) except use a time step dt = 0.1 sec Print an error message if h = 3000 ft is not reached Use fprintf to display the result ii) Problem 5 i) Add the additional input function get_h_des to the list of input parameters and thern determine the time at which h = 3000 on the way up. Use a WHILE loop technique and a time step dt = 0.05sec. Print an error message if h = 3000 ft is not reached Use fprintf to display the result ii)

Explanation / Answer

use below code :

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=0.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;
%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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote