While checking some matrix multiplication operations, I came across a strange behavior. I get different results when I perform the multiplication "by hand" (using the product and the sum) and when using the matrix multiplication operator %*%.
c <- 1:10
a <- 100^(0:9)
p1 <- sum(a*c)
p2 <- a%*%c
p1==p2
[,1]
[1,] FALSE
p1-p2
[,1]
[1,] -2048
However, when I use any other value for a (e.g., a <- 101^0:9) , I do get the same results:
c <- 1:10
a <- 101^(0:9)
p1 <- sum(a*c)
p2 <- a%*%c
p1==p2
[,1]
[1,] TRUE
p1-p2
[,1]
[1,] 0
Any idea why this is happening?
Thank you, Pedro