how to get rid of imaginary numbers, after a root.

조회 수: 61 (최근 30일)
oskar
oskar 2013년 10월 25일
댓글: Kumaresh Kumaresh 2022년 6월 14일
hi, i´m a beginner in matlab and i have been making a tracejtory with a basketball. my problem now is with the time.
This is a part of my script. My speed and angle are two vectors, because of the vectors sometimes the roots will be an imaginary number and (at=atand....) will get error. How do I do if i only want real numbers to go into at=atand....
time = roots([-g./2, v0y, y0-H]);
time = max(time);
at=atand((h0*cos(V))/((h0*sin(V))-(g*tid)));
thanks for your time=)

채택된 답변

Muruganandham Subramanian
Muruganandham Subramanian 2013년 10월 25일
time = roots([-g./2, v0y, y0-H]);
time = max(time);
time=real(time);
at=atand((h0*cos(V))/((h0*sin(V))-(g*tid)))
  댓글 수: 2
oskar
oskar 2013년 10월 25일
thanks that is what i needed=)
Kumaresh Kumaresh
Kumaresh Kumaresh 2022년 6월 14일
Thanks ^^ Thas helps

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

추가 답변 (2개)

Simon
Simon 2013년 10월 25일
Hi!
What do you expect, physically? Your trajectory is a parabola with negative prefactor in front of t^2. So, the apex is the highest point of your curve. If it is negative you won't find real roots of the polynom. Pyhsically this means you throw your ball from below the earth's surface and it is falling downwards ... ;-)

oskar
oskar 2013년 10월 25일
I know, thats why i have two vectors wich will eventually get it into the baskethoop, but when the all the numbers "time" is going into the at=atand... i don't want the imaginary numbers to go into at=atand...
  댓글 수: 1
Simon
Simon 2013년 10월 25일
If you just want to skip the atand command for imaginary time you may surround it with
if isreal(time)
atand ...
end

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by