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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by