Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you find the condition number in Eigen?

Tags:

math

eigen

In Matlab there are cond and rcond, and in LAPACK too. Is there any routine in Eigen to find the condition number of a matrix?

I have a Cholesky decomposition of a matrix and I want to check if it is close to singularity, but cannot find a similar function in the docs.

UPDATE: I think I can use something like this algorithm, which makes use of the triangular factorization. The method by Ilya is useful for more accurate answers, so I will mark it as correct.

like image 469
aledalgrande Avatar asked Mar 14 '23 05:03

aledalgrande


1 Answers

Probably easiest way to compute the condition number is using the expression:

cond(A) = max(sigma) / min(sigma)

where sigma is an array of singular values, the result of SVD. Eigen author suggests this code:

JacobiSVD<MatrixXd> svd(A);
double cond = svd.singularValues()(0) 
    / svd.singularValues()(svd.singularValues().size()-1);

Other ways are (less efficient)

cond(A) = max(lambda) / min(lambda)
cond(A) = norm2(A) * norm2(A^-1)

where lambda is an array of eigenvalues.

It looks like Cholesky decomposition does not directly help here, but I cant tell for sure at the moment.

like image 88
Ilya Popov Avatar answered May 03 '23 22:05

Ilya Popov