Search code examples
matlab

MatLab returning different trigonometric answers than calculator?


I'm having some difficulty trying to comprehend the answers that Matlab and my calculator are returning from sinusoidal functions.

Firstly, I figured that pi/2 and 90 deg are analogous, but when I pass them into a cosine function I get these two outputs:

  • Calculator: cos(90) = 0
  • Calculator: cos(pi/2) = 0.9996242169
  • Matlab: cos(90) = -0.4481
  • Matlab: cos(pi/2) = 6.1232e-17

I have been referencing the unit circle and things don't seem to stack up. I am fairly new to maths, so maybe I may be doing something wrong. I've been practising with the sine function and this is a lot closer to my calculator results:

  • Matlab: sin(90) = 0.8940
  • Matlab: sin(pi/2) = 1

Solution

  • If you want to provide angle in degrees then use cosd and sind and if angle is in radians then use cos and sin.

    cos(0) and cosd(0) are producing 1 on my computer. However cos(pi/2) is producing 6.1232e-17 and cosd(90) is producing 0.

    you can check matlab specification which number is close to 0.