How to compute smallest non-zero eigenvalue

Viewed 1120

Given a positive semi-definite matrix M I would like to find its smallest non-zero eigenvalue. In python this code looks tempting

import numpy as np
(w,v) = np.linalg.eigh(M)
minw = np.amin(w)
if (np.isclose(minw,0) and minw > 0):
    print M, minw

Here is an example small input matrix.

[ 6  2 -4 -2]
[ 2  6  0 -6]
[-4  0  6  0]
[-2 -6  0  6]

Unfortunately if you try this you will get 8.90238403828e-16. I don't know in general how to tell if very small numbers are meant to be zero or not.

How can you find the smallest non-zero eigenvalue of a matrix (and be sure it really is non-zero)?

2 Answers

First you might want to check that your matrix is invertible. One way to do this is to calculate the determinant with numpy.linalg.det. If it isn't invertible, you can project this matrix into the space orthogonal to the kernel. The projected matrix will now be invertible, with the property that the eigenvalue of smallest magnitude will be the smallest (in magnitude) non-zero eigenvalue of the original matrix.

Related