I have a matrix emat
generated by taking the sum of outer products of vectors. It should be symmetric and positive definite. I am finding that
solve(emat) %*% solve(emat)
generates a different result from
bmat <- solve(emat)
bmat %*% t(bmat)
In fact, the two differ quite substantially (printed output of emat
is shortened by R).
> emat
V1 V2 V3
1 170.2939 15.77391 110.75499
2 15.7739 444.57862 8.87082
3 110.7550 8.87082 72.03669
> solve(emat) %*% solve(emat) - bmat %*% t(bmat)
1 2 3
V1 -1024 48.00000 0
V2 8 -0.21875 0
V3 2048 -72.00000 0
But this should not be the case.
Is this a bug? Or is it an issue with precision? Or does it have to do with how R handles matrices stored in memory?