Does sin() have an error?

From the command line: >> 6*pi
ans =
18.8496
>> sin(ans)
ans =
-7.3479e-16
Really? Is that a rounding error? Is there a way to get the correct value?

 채택된 답변

Matt Fig
Matt Fig 2012년 10월 24일
편집: Matt Fig 2012년 10월 24일

1 개 추천

That is the correct value for floating point arithmetic.
sin(pi) % Same as your example.
If you want to get the exact value, use the symbolic toolbox.
double(vpa('sin(pi)'))

댓글 수: 1

Patrick Kelley
Patrick Kelley 2012년 10월 24일
Yeah, I said rounding error when I meant precision error. Good old floating point binary format... I haven't used the symbolic toolbox much but I'll give it another look. Thanks for the quick answer.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by