Det matrix returns 0 in matlab

I was given a very large matrix (I cannot change the values ​​of the matrix), and I need to calculate the inverse of the (covariance) matrix.

Sometimes I get an error

 Matrix is close to singular or badly scaled.
     Results may be inaccurate

In these situations, I see that det returns 0.

Before calculating the inversion of the (covariance matrix), I want to check the value of det and do something like this

covarianceFea=cov(fea_class);
covdet=det(covarianceFea);
if(covdet ==0)
    covdet=covdet+.00001;
    %calculate the covariance using this new det
end 

Is it possible to use the new det and then use it to calculate the inverse covariance matrix?

+5
source share
3 answers

. - , , . . , . ? , . , .

- . ? , MATLAB . , , . ,

>> realmin
ans =
  2.2251e-308

( , MATLAB , , 1e-323.) , , , , , MATLAB , .

>> A = 1e-323
A =
  9.8813e-324

>> A = 1e-324
A =
     0

? , :

M = eye(1000);

M - , . , det , .

>> det(M)
ans =
     1

, . ? !!!!!!!!!!!!!!!!!!!!!!!! . .

>>     det(M*0.1)
ans =
     0

. . MATLAB , . , 1-1000. . Gosh, 1e-1000 , , , , MATLAB . , , , , . ? . ? , , .

. , cond rank. , ?

>> rank(M)
ans =
        1000

>> rank(M*.1)
ans =
        1000

, , , , . cond, M.

>> cond(M)
ans =
     1

>> cond(M*.1)
ans =
     1

. , , det . .

+16

Woodchips , . , -, , : Matlab?, OP , 1, !

det(A)=1 , , . , det(A)=∏i=1:n λi. λ1=M, λn=1/M λi≠1,n=1 det(A)=1. , M → ∞, cond(A) = M2 → ∞ λn → 0, , .

MATLAB :

A = eye(10);
A([1 2]) = [1e15 1e-15];

%# calculate determinant
det(A)
ans =

     1

%# calculate condition number
cond(A)
ans =

   1.0000e+30
+5

In such a scenario, calculating the inverse is not a good idea. If you just need to do this, I would suggest using this to increase display accuracy:

format long;

Another suggestion might be to try to use SVD matrices and tinker with singular values ​​there.

A = U∑V'
inv(A) = V*inv(∑)*U'

Σ is the diagonal matrix in which you will see one of the diagonal entries close to 0. Try playing with this number if you want some kind of approximation.

+1
source

All Articles