Starting from:
$30

$24

Pre-Laboratory 9 Solution

PURPOSE: To introduce the use of a Function.

STEP 1: Create the script file rocket2h2.m as given in the sample code. Please note that some sections of code are reused and can simply be copied and pasted, A PERFECT SCENARIO FOR USE OF A FUNCTION!!!

STEP 2:

Create the script file Lastname_prelab9.m as given in the sample code.
Run Lastname_prelab9.
Enter 6 for the burn time, 6000 for the desired height.
Rerun Lastname_prelab9 but this time enter 7 and 5000.






%ENGR15100 Prelab9.m

%

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_ph_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







Laboratory 9_Step 1




PURPOSE: To motivate the use of a function. Each Script file below is to be stand alone and should begin with clc and clear.




Problem 1

Based on the rocket code of pre-lab 9, write a script file firstname_lastname_lab9_probem1.m to:

Ask the user to enter the values of the rocket mass m in lbs, engine force f in lbs, and the engine burn time b in seconds. In the input prompt strings specify that m is to be between 5 and 15 lb, f is to be between 50 and 500 lbs, and b between 5 and 20 seconds. Note that the numbers do not have to be integers.
Calculate the flight parameters of rocket velocity at engine shut down v_b, rocket altitude at engine shut down h_b, peak altitude h_p, and the time to peak altitude t_p.
Display (using fprintf) messages with values of the four variables calculated above, including the correct associated units.



Problem 2

Based on the rocket code of pre-lab 8, write a script file firstname_lastname_lab9_problem2.m to:

Calculate the altitude h from the time of launch to ground impact. Again ask the user to input the values as in Problem 1, and again use dt = 0.1 s.
Create the plot of h versus t in figure 2, add x and y labels, title, and a grid.



Problem 3

Based on the rocket code of pre-lab 8, write a script file firstname_lastname_lab9_problem3.m to:

Calculate the velocity v and altitude h of the rocket from the time of launch to ground impact. Use inputs and values as before.
Create a two-row, one-column subplot in figure 3, where subplot one shows altitude h versus time, while subplot two shows velocity v versus time.



Problem 4

Based on the rocket code of pre-lab 8, write a script file firstname_lastname_lab9_problem4.m to:

Determine the time at which h =3000 ft on the way up. Use a FOR loop technique, a time step dt = 0.1 s, and other values and inputs as before. Print an error message if h = 3000 ft is not reached.
Use fprintf to display the result.



Problem 5

Based on the rocket code of pre-lab 8, write a script file firstname_lastname_lab9_problem5.m to:

Determine the time at which h =3000 ft on the way up. Use a WHILE loop technique and a time step of dt = 0.05 s, and other values and inputs as before. 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.

More products