5. Many solid-fuel rocket engines consist of three stages. Once the first stage
ID: 2087397 • Letter: 5
Question
5. Many solid-fuel rocket engines consist of three stages. Once the first stage burns out, it separates from the missile and the second stage lights. Then the second stage burns out and separates, and the third stage lights. Finally, once the third stage burns out, it also separates from the missile. Assume that the following data approximately represent the times during which each stage burns: Stage 0-100 seconds Stage 2 101-170 seconds Stage 3 171-260 seconds Write a function that reads a single input (time) to determine whether the missile is in Stage 1 flight, Stage 2 flight, Stage 3 flight, or free flight (unpowered). If the user enters a negative time, the function should return an error message. You should run and show all possible test cases that your function file works.Explanation / Answer
time=input('Time since the rocket was launched: ');
stage = 0;
if time < 100
stage = 1;
elseif time < 170
stage = 2;
elseif time < 260
stage = 3;
elseif time < 0
fprintf('error')
end
fprintf('The rocket is in stage%d ', stage)
out put:-
Time since the rocket was launched : 50
The rocket is in stage 1
Time since the rocket was launched :150
The rocket is in stage 2
Time since the rocket was launched :250
The rocket is in stage 3
Time since the rocket was launched :-100
error
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.