I would like to do the summation of product of all the elements of two vectors in R language, but something goes wrong. This is my data definition:
> alpha <- 1/24
> a <- c(-5, -2, 1)
> b <- c(alpha*3, alpha*2, 1-5*alpha)
Then I'm trying:
> result <- sum(a*b)
> result
[1] 8.326673e-17
And I expect the result is zero, but it's not.
To explain better, I would like to compute this summation:
(a[1]*b[1]) + (a[2]*b[2]) + (a[3]*b[3])
That should be:
(-5*alpha*3)+(-2*alpha*2)+(1*(1-alpha*5)) = (-5*1/24*3)+(-2*1/24*2)+(1*(1-5*1/24)) = 0