Find the time when a parabolic function starts to decrease.

Hello,
My task is to write a script that will find the time when a parabolic function (height, a function of time) reaches its max.
clear all
t=0;
for time=0:0.5:30;
if height(time)>=height(time-0.5)
t=t+0.5;
end
end
disp(t)
height(time-0.5) wouldn't execute so here is my second code
clear all
t=0;
for time=0:0.5:30;
e=0.5:0.5:29;
time2=[0 e];
while height(time)>height(time2)
t=t+0.5;
end
end
disp(t)
this code does not work either. How can i utilize max( ) function in here? And what is the best way to do this kind of loop?
Thanks!

 채택된 답변

Walter Roberson
Walter Roberson 2016년 10월 2일

0 개 추천

What is height here? If it is a vector then you cannot use height(time) you can only use height(SomePositiveIntegerIndex) . But once you have found the appropriate positive integer index, you can use it to figure out what the corresponding time is.

댓글 수: 3

height is just a function of time, like a projectile function. if i plot t and f(t) its just an upside-down parabola. (both are 1x61 elements)
I can definitely get the max height using max(height(time)). but how would i solve it back and get t at max? quadratic formula? I could also do a loop of the derivative==0, but how do i incorporate time? I think there is an easier way with loops.
[maxheight, idx] = max(height(time))
where time is a vector. Then time(idx)
thanks for that command, I haven't used it before. It gave me an index on the time vector corresponding to the seconds that I needed.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2016년 10월 2일

댓글:

2016년 10월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by