In R, I have a 3000x4 matrix that looks like the following:
[1,] 8.458792e-02 6.915341e-02 2.179035e-01 8.458792e-02
[2,] 1.933362e-01 2.895261e-01 2.836058e-01 1.933362e-01
[3,] 2.706257e-02 3.233158e-02 7.077421e-02 2.706257e-02
[4,] 2.621281e-01 1.448730e-01 5.983300e-01 2.621281e-01
[5,] 2.018450e-01 2.322246e-01 1.634069e-01 0.000000e+00
[6,] 2.990089e-01 4.956391e-01 3.123204e-01 2.990089e-01
[7,] 1.244709e+00 -4.636184e-01 2.340081e+00 1.244709e+00
[8,] -1.124598e+00 -1.761734e+00 2.832896e-01 0.000000e+00
[9,] 1.394569e-02 2.337716e-02 3.243019e-02 1.394569e-02
[10,] -2.134538e-01 -1.295015e-01 1.296246e-01 0.000000e+00
[ reached getOption("max.print") -- omitted 2990 rows ]
Here, let me call the matrix "C".
I am suffering from a problem that the matrix product returns NaNs:
> t(C)%*%C
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN NaN NaN NaN
But, if I try to the calculation using only the first 100 rows, the problem does not occur:
>t(C[1:100,])%*%C[1:100,]
27.063320 8.051414 27.027122 15.340364
8.051414 10.571046 5.213047 3.521941
27.027122 5.213047 41.211831 23.785906
15.340364 3.521941 23.785906 15.340364
So, why does this happens? and how can I solve this problem?
(Of course, my code has more details but the only source where the problem happens is just the matrix product aforementioned, thus, I think additional detail may be not informative to solve this problem.)