Hi. I recently tried the following in R 2.5.1 on Windows XP:>ev2<-c(0.8,-0.6) >ev1<-c(0.6,0.8) >ev1%*%ev2[,1] [1,] -2.664427e-17>sum(ev1*ev2)[1] 0>(I got the same result with R 2.4.1 on a different Windows XP machine.) I expect this issue is very familiar and probably has been discussed in this forum before. Can someone please point me to some documentation or discussion about this? Is there some standard way to get the "correct" answer from %*%? Thanks! -- TMK -- 212-460-5430 home 917-656-5351 cell
This is giving you exactly what you are asking for. The operator * does element by element multiplication. So, .48 + -.48 =0, right? Is there another mathematical possibility you were expecting?> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Talbot Katz > Sent: Friday, July 27, 2007 6:31 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Matrix Multiplication, Floating-Point, etc. > > Hi. > > I recently tried the following in R 2.5.1 on Windows XP: > > >ev2<-c(0.8,-0.6) > >ev1<-c(0.6,0.8) > >ev1%*%ev2 > [,1] > [1,] -2.664427e-17 > >sum(ev1*ev2) > [1] 0 > > > > (I got the same result with R 2.4.1 on a different Windows XP > machine.) > > I expect this issue is very familiar and probably has been > discussed in this forum before. Can someone please point me > to some documentation or discussion about this? Is there > some standard way to get the "correct" > answer from %*%? > > Thanks! > > -- TMK -- > 212-460-5430 home > 917-656-5351 cell > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
7.31 Why doesn't R think these numbers are equal? On Fri, 27 Jul 2007, Talbot Katz wrote:> Hi. > > I recently tried the following in R 2.5.1 on Windows XP: > >> ev2<-c(0.8,-0.6) >> ev1<-c(0.6,0.8) >> ev1%*%ev2 > [,1] > [1,] -2.664427e-17 >> sum(ev1*ev2) > [1] 0 >> > > (I got the same result with R 2.4.1 on a different Windows XP machine.) > > I expect this issue is very familiar and probably has been discussed in this > forum before. Can someone please point me to some documentation or > discussion about this? Is there some standard way to get the "correct" > answer from %*%? > > Thanks! > > -- TMK -- > 212-460-5430 home > 917-656-5351 cell > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901