Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help this assignment is due very soon and i cant fix my work. there are many files because of all the functions and problems

please help this assignment is due very soon and i cant fix my work. there are many files because of all the functions and problems but its very begineers level. ******************************************************************************************************************************************Pre-Laboratory 9 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: 1. Create the script file Lastname_prelab9.m as given in the sample code. 2. Run Lastname_prelab9. 3. Enter 6 for the burn time, 6000 for the desired height. 4. 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_p>h_des %do-able! h=0; k=0; t=0; while h 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:

i) 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.

ii) 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.

iii) 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:

i) 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. ii) 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:

i) Calculate the velocity v and altitude h of the rocket from the time of launch to ground impact. Use inputs and values as before. ii) 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:

i) 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.

ii) 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:

i) 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.

ii) 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. Laboratory 9_step 2 PURPOSE: To further introduce the use of functions STEP 1: Create six function files. 1. %Create the function file lastname_get_b.m function b= lastname_get_b () b=input('Enter desired engine burn time b in seconds '); disp(' ') 2. %Create the function file lastname_get_f.m function f= lastname_get_f () f=input('Enter desired engine force f in lbs '); disp(' ') 3. %Create the function file lastname_get_dt.m function dt= lastname_get_dt () dt=input('Enter desired simulation time step dt in sec '); disp(' ') 4. %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(' ') 5. %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; 6. %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

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.

ii) Display (using fprintf) messages with values of the variables calculated above.

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. ii) 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.

ii) 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.

ii) Use fprintf to display the result.

Problem 5

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 WHILE loop technique and a time step dt = 0.05sec. Print an error message if h = 3000 ft is not reached

. ii) Use fprintf to display the result.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago