[Rd] Determinant function (PR#9715)
savicky at cs.cas.cz
Mon Jun 4 14:40:13 CEST 2007
> The function ''det'' works improperly for a singular matrix and returns a
> non-zero value even if ''solve'' reports singularity. The matrix is very simple
> as shown below.
> A <- diag(rep(c(64,8), c(8,8)))
> A[9:16,1] <- 8
> A[1,9:16] <- 8
> # -196608
> #Error in solve.default(A) : system is computationally singular: reciprocal
> condition number = 2.31296e-18
The "det" function cannot work properly in the limited precision
of floating point numbers. May be, "det" could also do a test
of computational singularity and refuse to compute the value
similarly as "solve" does.
The eigen-values of your matrix are
 7.200000e+01 6.400000e+01 6.400000e+01 6.400000e+01 6.400000e+01
 6.400000e+01 6.400000e+01 6.400000e+01 8.000000e+00 8.000000e+00
 8.000000e+00 8.000000e+00 8.000000e+00 8.000000e+00 8.000000e+00
The last value is not zero due to rounding. The determinant is the product
of eigenvalues, so we get something large.
The problem may also be seen as follows:
This is close to zero as it should be, however, det(A) = det(A/8)*8^16,
and this is what we really get:
There are even matrices closer to a diagonal matrix than A with
a similar problem:
> B <- 20*diag(16); B[1:2,1:2] <- c(25,35,35,49); det(B);
All the best, Petr.
More information about the R-devel