I have no idea how to use the m-file function

24 ビュー (過去 30 日間)
Hailey
Hailey 2014 年 10 月 14 日
コメント済み: Image Analyst 2018 年 3 月 31 日
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 件のコメント
the cyclist
the cyclist 2014 年 10 月 14 日
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.

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2014 年 10 月 14 日
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 件のコメント
Callum MaxWell
Callum MaxWell 2018 年 3 月 29 日
I am also having trouble with the same question. I was not properly taught on this subject. Can someone please help me.
Image Analyst
Image Analyst 2018 年 3 月 31 日
Callum, not sure what to tell you without additional information. See this link

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by