How to find if a matrix is Singular in Matlab

前端 未结 5 1928
北海茫月
北海茫月 2020-12-18 21:23

I use the function below to generate the betas for a given set of guess lambdas from my optimiser.

When running I often get the following warning message:

相关标签:
5条回答
  • 2020-12-18 21:28

    Condition number (Maximal singular value/Minimal singular value) is another good method:

      cond(A)
    

    It uses svd. It should be as close to 1 as possible. Very large values mean that the matrix is almost singular. Inf means that it is precisely singular.

    Note that almost all of the methods mentioned in other answers use somehow svd :

    0 讨论(0)
  • 2020-12-18 21:34

    There are special tools designed for this problem, appropriately called "rank revealing matrix factorizations". To my best (albeit a little old) knowledge, a good enough way to decide whether a n x n matrix A is nonsingular is to go with

    det(A) <> 0 <=> rank(A) = n

    and use a rank-revealing QR factorization of A:

    AP = QR
    

    where Q is orthogonal, P is a permutation matrix and R is an upper triangular matrix with the property that the magnitude of the diagonal elements is decreased along the diagonal.

    0 讨论(0)
  • 2020-12-18 21:35

    You could compare the result of rank(G) with the number of columns of G. If the rank is less than the column dimension, you will have a singular matrix.

    0 讨论(0)
  • 2020-12-18 21:41

    rcond is the right way to go here. If it nears the machine precision of zero, your matrix is singular. I usually go with:

    if( rcond(A) < 1e-12 )
        % This matrix doesn't look good
    end
    

    You can experiment with a value that suites your needs, but taking the inverse of a matrix that is even close to singular with MATLAB can produce garbage results.

    0 讨论(0)
  • 2020-12-18 21:44

    you can also check this by:

    min(svd(A))>eps
    

    and verifying that the smallest singular value is larger than eps, or any other numerical tolerance that is relevant to your needs. (the code will return 1 or 0)

    Here's more info about it...

    0 讨论(0)
提交回复
热议问题