Eigenvalues: Conditioning and Pitfalls
Eigenvalues decide the stability of ODEs, the vibration frequencies of structures, the long-run behaviour of Markov chains and the principal components of data. Before computing them we should ask how sensitive they are. The answer depends strongly on the matrix: for symmetric matrices eigenvalues are always well conditioned, while for non-normal matrices they can be wildly sensitive.
Why not use the characteristic polynomial
Mathematically the eigenvalues are the roots of . Numerically this is a bad route: computing polynomial coefficients loses information, and polynomial roots can be extremely ill-conditioned (Conditioning of Problems). Libraries never do it. Instead they use similarity transformations (The QR Algorithm).
import numpy as np
lam = np.arange(1.0, 21.0)
A = np.diag(lam) # eigenvalues exactly 1..20
via_poly = np.sort(np.roots(np.poly(A)).real)
via_eig = np.sort(np.linalg.eigvals(A).real)
print(f"max error via characteristic polynomial: {np.max(np.abs(via_poly - lam)):.1e}")
print(f"max error via eigvals : {np.max(np.abs(via_eig - lam)):.1e}")max error via characteristic polynomial: 6.5e-02
max error via eigvals : 0.0e+00
Bauer-Fike: diagonalizable matrices
If and is a perturbation, every eigenvalue of satisfies
The condition number of the eigenvector matrix controls sensitivity. For symmetric (more generally, normal) matrices is orthogonal, , and eigenvalues move no more than the perturbation itself. For a nearly defective matrix is huge.
import numpy as np
rng = np.random.default_rng(41)
E = rng.normal(size=(6, 6)); E *= 1e-10 / np.linalg.norm(E, 2)
S = rng.normal(size=(6, 6)); S = S + S.T # symmetric
J = np.diag(np.ones(6)) + np.diag(np.ones(5), 1) # Jordan block, eigenvalue 1
for name, M in (("symmetric", S), ("Jordan block", J)):
ev = np.sort_complex(np.linalg.eigvals(M))
ev2 = np.sort_complex(np.linalg.eigvals(M + E))
print(f"{name:13s}: eigenvalues move by up to {np.max(np.abs(ev2 - ev)):.1e} for a perturbation of 1e-10")symmetric : eigenvalues move by up to 1.6e-11 for a perturbation of 1e-10
Jordan block : eigenvalues move by up to 1.0e-02 for a perturbation of 1e-10
For the Jordan block a perturbation of size moves the eigenvalue by about : here becomes about .
Non-normal matrices in practice
Matrices from fluid flow, Markov chains and some ODE discretizations are far from normal. Their eigenvalues may not tell the whole story: can grow by large factors before decaying even when all eigenvalues have negative real part. Pseudospectra (the sets where is large) describe such behaviour better.
Eigenvectors
Eigenvectors are sensitive when eigenvalues are close together: the condition number of an eigenvector grows like to the nearest other eigenvalue. When two eigenvalues coincide, only the invariant subspace is well defined, not individual vectors.
In software
np.linalg.eigh/scipy.linalg.eighfor symmetric/Hermitian matrices: faster, real eigenvalues sorted, orthonormal eigenvectors. Use it whenever the matrix is symmetric.np.linalg.eigfor general matrices;scipy.linalg.eig(..., left=True)also returns left eigenvectors, from which individual eigenvalue condition numbers can be computed.- Stability analysis of ODE solvers uses eigenvalues of the Jacobian (Stiff Equations).
Exercises
Exercise 1: Symmetric perturbation
A symmetric matrix is perturbed by a symmetric with . How far can its eigenvalues move?
Answer
At most .
Solution
For symmetric matrices (Weyl's theorem gives the same bound with each eigenvalue paired in order).
Exercise 2: Jordan block sensitivity
The matrix has eigenvalues . For how far do they move from 1?
Answer
.
Solution
, so : a change times larger than the perturbation.
Exercise 3: Condition of each eigenvalue (code)
For compute the eigenvalue condition numbers from right and left eigenvectors.
Answer
Both are about .
Solution
import numpy as np
from scipy.linalg import eig
A = np.array([[1.0, 1000.0], [0.0, 2.0]])
w, vl, vr = eig(A, left=True, right=True)
for k in range(2):
x, y = vr[:, k], vl[:, k]
print(round(w[k].real, 6), round(float(np.linalg.norm(x) * np.linalg.norm(y) / abs(y.conj() @ x)), 3))1.0 1000.0
2.0 1000.0
Test yourself
Why do libraries not compute eigenvalues as roots of the characteristic polynomial?
- It is too slow only
- Polynomial roots can be extremely sensitive to rounding of the coefficients
- It only works for 2x2 matrices
- It gives complex numbers
The eigenvalues of a symmetric matrix are…
- always ill-conditioned
- perfectly conditioned: they move at most by
- complex
- conditioned like
Bauer-Fike bounds eigenvalue movement by…
- with the eigenvector matrix