Why the answer is wrong ( SIMPLE TRIGONOMETRIC)

My code is:
function onex(y)
cos(y)*cos(y)-sin(y)*sin(y)
end
When I insert y=pi/4 The result is:
>> onex(pi/4)
ans =
2.2204e-16
Does anybody has any suggestions? Thank you in advance!

 Respuesta aceptada

Joseph Cheng
Joseph Cheng el 2 de Abr. de 2014
to try to get zero as you want, you may have to do it in degrees.
x= pi/4*180/pi;
cosd(x)*cosd(x)-sind(x)*sind(x)
will get you your 0. This is because pi is not exactly pi. http://www.mathworks.com/help/matlab/ref/pi.html

Más respuestas (0)

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Preguntada:

el 2 de Abr. de 2014

Comentada:

el 2 de Abr. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by