Does sin() have an error?

5 views (last 30 days)
Patrick Kelley
Patrick Kelley on 24 Oct 2012
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?

Accepted Answer

Matt Fig
Matt Fig on 24 Oct 2012
Edited: Matt Fig on 24 Oct 2012
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 Comment
Patrick Kelley
Patrick Kelley on 24 Oct 2012
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!