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
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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.