How to find if a matrix is Singular in Matlab

前端 未结 5 1958
北海茫月
北海茫月 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: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.

提交回复
热议问题