Info

此问题已关闭。 请重新打开它进行编辑或回答。

acosd returns complex number

4 次查看(过去 30 天)
Hi
I got a problem with matlab returning complex numbers when i use acosd().
Can i force matlab to give me a non-complex number?
Thanks
  4 个评论
John D'Errico
John D'Errico 2018-5-6
编辑:John D'Errico 2018-5-6
This may be an indication that your triangle is NOT in fact a triangle. For example, what triangle has sides of length 1, 2, and 10? Can that triangle exist? Does the triangle inequality apply here?
https://en.wikipedia.org/wiki/Triangle_inequality
John BG
John BG 2018-5-6
Hi Christian von Sprekelsen
this is John BG jgb2012@sky.com
1.-
While agreeing upon everything that Mr D'Erico has commented and answered to your question, I would like to remark that it's common mistake to use acosd when atand should be used.
Are you sure that the expression you are supposed to use is not
180-atand(2.7)
?
2.-
Would it be possible to know the triangle points, I will show you different ways to correctly extract all relevant angles and distances, the knowing the 3 defining points should be the start point, don't you agree?
3.-
Understanding that this question has been already closed by a forum contributor with higher rank, Christian if you send me by email the points of the triangle to analyse, we can discuss how to start a new question to solve the doubts that apparently have not yet been resolved.
Looking forward to receiving the triangle points, or the available details.
John BG

回答(1 个)

John D'Errico
John D'Errico 2018-5-6
编辑:John D'Errico 2018-5-6
No. Period. NO. Your problem is that you apparently don't appreciate what acosd means.
Think about what acosd is supposed to do. Start with the cos function, or cosd, since you seem to prefer that version in degrees.
The cosine of any number is a periodic function. It generates a number between -1 and 1, so think about the standard cosine wave, oscillating forever from -1 to 1 and back again. Gets pretty boring, I know.
ezplot(@cosd,[-720,720])
grid on
Now, what does the acosd function do? For ANY number in the interval -1 to 1, it tells you the angle in degrees that corresponds to the given value. It is an inverse cosine function, usually called the arc-cosine, thus acos and acosd.
ezplot(@acosd,[-1,1])
grid on
Now you want to know what acosd(2.7702) is. As a real number. There is NO real number such that when you take the cosine of it, you will get 2.7702. How much time did I just spend explaining that cos(x) NEVER generates greater than 1? So why would you hope that there is some number such that acosd(2.7702) would return a real number?
acosd(1)
ans =
0
acosd(1 + eps)
ans =
0 + 1.2074e-06i
So if we get acosd(1), we get 0, as expected. But increase the input by just a tiny amount, so it is greater than 1, and we suddenly start getting an imaginary part. The real part will always be zero when we do this.
In fact, all of the common trig functions have extensions into the complex plane, so the only solution that works is an imaginary number when the input is greater than 1.
D = acosd(2.7702)
D =
0 + 96.129i
cosd(D)
ans =
2.7702
for inputs less than -1, even by a tiny amount, we will get something like this:
acosd(-1 - eps)
ans =
180 - 1.2074e-06i
essentially a real part of 180 degrees, ALWAYS, but with ALWAYS some imaginary part.
As we see in all this, acosd worked perfectly. But there is no possible way to get it to give you a real number, without an imaginary part. That is just mathematics.

Community Treasure Hunt

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

Start Hunting!

Translated by