[R] Question about converting from square roots to decimals and back
Marc Schwartz
marc_schwartz at comcast.net
Sat Jan 20 20:09:19 CET 2007
On Sat, 2007-01-20 at 14:00 -0500, Robert Barber wrote:
> Hi,
>
> I apologize if there is a simple answer to this question that I've
> missed. I did search the mailing list but I might not have used the
> right keywords. Why does sum(A3^2) give the result of 1, but
> sum(A3^2)==1 give the result of FALSE?
>
> > A3<-matrix(nrow=3,c(1/(2^.5),1/(2^.5),0))
> > A3
> [,1]
> [1,] 0.7071068
> [2,] 0.7071068
> [3,] 0.0000000
> > sum(A3^2)
> [1] 1
> > sum(A3^2)^.5
> [1] 1
> > sum(A3^2)==1 # here's the part I don't understand
> [1] FALSE
> > sum(A3^2)^.5==1 # here's the part I don't understand
> [1] FALSE
>
> I realize that it has something to do with the conversion of the square
> roots into decimals. But shouldn't it then give me some number other
> than 1 as the result for sum(A3^2)? Are there other ways to do this
> than what I've tried? I'm trying to confirm that A3 is a unit vector.
>
> Thank you for your help.
>
> Bob B.
See R FAQ:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
> print(sum(A3^2)^.5, 20)
[1] 0.99999999999999988898
HTH,
Marc Schwartz
More information about the R-help
mailing list