MATLAB sin() vs sind()

barney picture barney · Oct 17, 2013 · Viewed 14.3k times · Source

I noticed that MATLAB has a sin() and sind() functions. I learnt that sin() accepts the angle in radians and sind() accepts the angle in degrees. The only difference I know is sind(180) gives 0 but sin(pi) doesn't:

>> sin(pi)
ans =
  1.2246e-016
>> sind(180)
ans =
     0

What boggles me is whether there is any scenarios or guidelines to choose between using sin() or sind()?

Answer

Shai picture Shai · Oct 17, 2013

From the documentation of sind:

For integers n, sind(n*180) is exactly zero, whereas sin(n*pi) reflects the accuracy of the floating point value of pi.

So, if you are extremely troubled with the fact that sin( pi ) is not precisly zero, go ahead and use sind, but in practice it is just a wrap-around sin so you actually add a tini-tiny bit of overhead.

Personally, I prefer the elegance of radians and use sin.