$24
PURPOSE: To further introduce the use of functions
STEP 1:
Create six function files.
%Create the function file lastname_get_b.m
function b= lastname_get_b ()
b=input('Enter desired engine burn time b in seconds ');
disp(' ')
%Create the function file lastname_get_f.m
function f= lastname_get_f ()
f=input('Enter desired engine force f in lbs ');
disp(' ')
%Create the function file lastname_get_dt.m
function dt= lastname_get_dt ()
dt=input('Enter desired simulation time step dt in sec ');
disp(' ')
%Create the function file lastname_get_h_des.m
function h_des= lastname_get_h_des ()
h_des=input('Enter desired altitude h_des in feet ');
disp(' ')
4a. %Create the function file lastname_get_m.m
function m = lastname_get_m ()
m=input('Enter desired rocket weight m in pounds ');
disp(' ')
%Create the function file lastname_calc_perf.m
function [v_b,h_b,t_p,h_p]=lastname_calc_perf (b,m,f,g)
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;
%Create the function file lastname_calc_hv.m
function [h,v]=lastname_calc_hv (b,m,f,g,t,h_b,v_b)
if t<=b
h= 0.5*(f/m-g)*t^2;
v=(f/m-g)*t;
else
h= h_b-.5*g*(t-b)^2+v_b*(t-b);
v=v_b-g*(t-b);
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
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.
Problem 2
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.
Create the plot in figure 2, add x and y labels, title, and a grid.
Problem 3
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.
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
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.
Problem 5
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 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.
SUBMITTING YOUR LAB:
Submit your lab by uploading .m file using the Blackboard Assignment feature no later than the date specified.