# How can I estimate the condition number of a large sparse matrix using PETSc?

I have a PETSc Mat and would like to estimate its condition number.

-

For small matrices, the condition number can be reliably computed using the singular value decomposition. Do a KSPSolve() with the matrix and run with -pc_type svd -pc_svd_monitor.

For larger matrices, you can estimate the condition number using a Krylov method. For example, the Arnoldi iteration performed by GMRES incrementally computes a Hessenberg decomposition. The extremal singular values and eigenvalues of the Hessenberg matrix are good approximations to those of the original matrix. To have PETSc estimate eigenvalues this way, run with

-ksp_monitor_singular_value -ksp_type gmres -ksp_gmres_restart 1000 -pc_type none


These options say to estimate the extremal singular values on each Krylov iteration. GMRES is used to compute the Krylov space (you could also use CG) with a huge restart. At restarts, GMRES discards the current Krylov space, so all the progress on singular value estimates is lost in a restart. The final option -pc_type none says to perform this iteration on the unpreconditioned matrix. By default, the preconditioned operator ($P^{-1} A$ or $A P^{-1}$) would be used, so you would end up with an estimate for the preconditioned operator.

This will generally be accurate for the largest singular values, but may overestimate the smallest singular value unless the method has converged. If you have a solver for the matrix (e.g. using KSPSolve()), then you can estimate the smallest singular value of $A$ using the same procedure applied to $A^{-1}$.

Use SLEPc if you need more accurate estimates of the smallest singular value (and for all other eigenvalue and singular value problems).

-