[R] strange result of acos
(Ted Harding)
Ted.Harding at nessie.mcc.ac.uk
Tue Mar 29 14:27:11 CEST 2005
On 29-Mar-05 Ted Harding wrote:
> The explanation is:
>
> sin(10.74*pi/180)**2
> +(cos(10.74*pi/180)*cos(10.74*pi/180)
> *cos(0*pi/180))
> -1
>
> [1] 2.220446e-16
>
> I.e. the expression, as internally evaluated, is very
> slightly greater than 1. When you multiply ss by
> 0.999999999, you bring it back down a bit.
>
> Theoretically, of course, it is sin(t)^2 + cos(t)^2,
> which should be exactly 1, but you can't count on it
> in digital computation. As you suspected, it is indeed
> a question of precision.
Just to make more explicit what's happening here:
t<-0.01*(0:200)*pi
sin(t)^2 + cos(t)^2 -1
##[output omitted]
unique(sin(t)^2 + cos(t)^2 -1)
##[1] 0.000000e+00 -1.110223e-16 2.220446e-16
2^(-53)
##[1] 1.110223e-16
so the error is either +2^(-52) or -2^(-53)
Best wishes,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 29-Mar-05 Time: 12:27:11
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list