I have no idea how to use the m-file function
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
A rocket is launched vertically upwards. At time t = 0, the rocket’s engine shuts down. At that time, the rocket has reached an altitude of 500 m and is rising at a velocity of 125 m/s. Gravity then takes over. The height of the rocket as a function of time is: h(t)= −9.8 2 t2 + 125 t + 500 , for t ≥ 0 a. Create a function M-file called height.m that accepts time t as an input and returns the height h of the rocket, with syntax, h = height(t) Add the following line at the end of your M-file, h(h<0) = 0; The syntax of this command will be explained later, but it ensures that the height never gets negative, since the ground is at zero height. Use your function in your solutions to the rest of this problem. b. Plot height versus time for times from 0 to 30 seconds. Use an increment of 0.01 seconds in your time vector. c. Find the time (in sec) when the rocket starts to fall back to the ground, in two ways, (i) using the max function, and (ii) using fminbnd. Determin the maximum height in meters and add the maximum point on the previous graph. d. Using the function fzero, with an initial search point at t = 20 sec, determine the time, sau tg in seconds, when the rocket hits ground, and place it on the above graph. See an example graph at the end.
1 Kommentar
the cyclist
am 14 Okt. 2014
If you are expected to use MATLAB in your course, and you have NO idea how to use MATLAB, I think you should be talking to your teacher, not us.
Antworten (1)
Image Analyst
am 14 Okt. 2014
Here's some hints. The first line of height.m will be
function h = height(t)
and the last lines will be
% Make sure heights don't go negative.
% If it is negative, set height equal to zero.
h(h<0) = 0;
just as the problem statement clearly spelled out. To call it from a test harness function:
t = 0 : 0.01 : 30;
for k = 1 : length(t)
h(k) = height(t(k));
end
plot(t, h, 'bo-', 'LineWidth', 2);
grid on;
4 Kommentare
Callum MaxWell
am 29 Mär. 2018
I am also having trouble with the same question. I was not properly taught on this subject. Can someone please help me.
Image Analyst
am 31 Mär. 2018
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!