Eigenvalue algorithm

In numerical analysis, one of the most important problems is designing efficient and stable algorithms for finding the eigenvalues of a matrix. These eigenvalue algorithms may also find eigenvectors.

Eigenvalues and eigenvectors
Given an $n × n$ square matrix $A$ of real or complex numbers, an eigenvalue $λ$ and its associated generalized eigenvector $v$ are a pair obeying the relation


 * $$\left(A - \lambda I\right)^k {\mathbf v} = 0,$$

where $v$ is a nonzero $n × 1$ column vector, $I$ is the $n × n$ identity matrix, $k$ is a positive integer, and both $λ$ and $v$ are allowed to be complex even when $A$ is real. When $k = 1$, the vector is called simply an eigenvector, and the pair is called an eigenpair. In this case, $Av = λv$. Any eigenvalue $λ$ of $A$ has ordinary eigenvectors associated to it, for if $k$ is the smallest integer such that $(A − λI)^{k} v = 0$ for a generalized eigenvector $v$, then $(A − λI)^{k−1} v$ is an ordinary eigenvector. The value $k$ can always be taken as less than or equal to $n$. In particular, $(A − λI)^{n} v = 0$ for all generalized eigenvectors $v$ associated with $λ$.

For each eigenvalue $λ$ of $A$, the kernel $ker(A − λI)$ consists of all eigenvectors associated with $λ$ (along with 0), called the eigenspace of $λ$, while the vector space $ker((A − λI)^{n})$ consists of all generalized eigenvectors, and is called the generalized eigenspace. The geometric multiplicity of $λ$ is the dimension of its eigenspace. The algebraic multiplicity of $λ$ is the dimension of its generalized eigenspace. The latter terminology is justified by the equation


 * $$p_A\left(z\right) = \det\left( zI - A \right) = \prod_{i=1}^k (z - \lambda_i)^{\alpha_i},$$

where $det$ is the determinant function, the $λ_{i}$ are all the distinct eigenvalues of $A$ and the $α_{i}$ are the corresponding algebraic multiplicities. The function $p_{A}(z)$ is the characteristic polynomial of $A$. So the algebraic multiplicity is the multiplicity of the eigenvalue as a zero of the characteristic polynomial. Since any eigenvector is also a generalized eigenvector, the geometric multiplicity is less than or equal to the algebraic multiplicity. The algebraic multiplicities sum up to $n$, the degree of the characteristic polynomial. The equation $p_{A}(z) = 0$ is called the characteristic equation, as its roots are exactly the eigenvalues of $A$. By the Cayley–Hamilton theorem, $A$ itself obeys the same equation: $p_{A}(A) = 0$. As a consequence, the columns of the matrix $\prod_{i \ne j} (A - \lambda_iI)^{\alpha_i}$ must be either 0 or generalized eigenvectors of the eigenvalue $I$, since they are annihilated by $$(A - \lambda_jI)^{\alpha_j}$$. In fact, the column space is the generalized eigenspace of $λ_{j}$.

Any collection of generalized eigenvectors of distinct eigenvalues is linearly independent, so a basis for all of $λ_{j}$ can be chosen consisting of generalized eigenvectors. More particularly, this basis $C^{n}$ can be chosen and organized so that If these basis vectors are placed as the column vectors of a matrix ${v_{i}}n i=1|undefined$, then $v_{i}$ can be used to convert $v_{j}$ to its Jordan normal form:
 * if $v_{k}$ and $k$ have the same eigenvalue, then so does $i$ for each $j$ between $v_{i}$ and $λ_{i}$, and
 * if $(A − λ_{i}I)v_{i} = v_{i−1}$ is not an ordinary eigenvector, and if $v_{1}$ is its eigenvalue, then $V = [v_{1} v_{2} ⋯ v_{n}]$ (in particular, $V$ must be an ordinary eigenvector).
 * $$V^{-1}AV = \begin{bmatrix} \lambda_1 & \beta_1 & 0 & \ldots & 0 \\ 0 & \lambda_2 & \beta_2 & \ldots & 0 \\ 0 & 0 & \lambda_3 & \ldots & 0 \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 0 & 0 & 0 & \ldots & \lambda_n \end{bmatrix},$$

where the $A$ are the eigenvalues, $λ_{i}$ if $β_{i} = 1$ and $(A − λ_{i+1})v_{i+1} = v_{i}$ otherwise.

More generally, if $β_{i} = 0$ is any invertible matrix, and $W$ is an eigenvalue of $λ$ with generalized eigenvector $A$, then $v$. Thus $(W'AW − λI)^{k} Wv''' = 0$ is an eigenvalue of $λ$ with generalized eigenvector $WAW$. That is, similar matrices have the same eigenvalues.

Normal, Hermitian, and real-symmetric matrices
The adjoint $Wv$ of a complex matrix $M^{*}$ is the transpose of the conjugate of $M$: $M$. A square matrix $M ^{*} = \overline{M} ^{T}$ is called normal if it commutes with its adjoint: $A$. It is called Hermitian if it is equal to its adjoint: $A^{*}A = AA^{*}$. All Hermitian matrices are normal. If $A^{*} = A$ has only real elements, then the adjoint is just the transpose, and $A$ is Hermitian if and only if it is symmetric. When applied to column vectors, the adjoint can be used to define the canonical inner product on $A$: $C^{n}$. Normal, Hermitian, and real-symmetric matrices have several useful properties:
 * Every generalized eigenvector of a normal matrix is an ordinary eigenvector.
 * Any normal matrix is similar to a diagonal matrix, since its Jordan normal form is diagonal.
 * Eigenvectors of distinct eigenvalues of a normal matrix are orthogonal.
 * The null space and the image (or column space) of a normal matrix are orthogonal to each other.
 * For any normal matrix $w ⋅ v = w^{*} v$, $w ⋅ v = v^{*} w$ has an orthonormal basis consisting of eigenvectors of $A$. The corresponding matrix of eigenvectors is unitary.
 * The eigenvalues of a Hermitian matrix are real, since $C^{n}$ for a non-zero eigenvector $A$.
 * If $(\overline{λ} − λ)v = (A^{*} − A)v = (A − A)v = 0$ is real, there is an orthonormal basis for $v$ consisting of eigenvectors of $A$ if and only if $R^{n}$ is symmetric.

It is possible for a real or complex matrix to have all real eigenvalues without being Hermitian. For example, a real triangular matrix has its eigenvalues along its diagonal, but in general is not symmetric.

Condition number
Any problem of numeric calculation can be viewed as the evaluation of some function $A$ for some input $A$. The condition number $f$ of the problem is the ratio of the relative error in the function's output to the relative error in the input, and varies with both the function and the input. The condition number describes how error grows during the calculation. Its base-10 logarithm tells how many fewer digits of accuracy exist in the result than existed in the input. The condition number is a best-case scenario. It reflects the instability built into the problem, regardless of how it is solved. No algorithm can ever produce more accurate results than indicated by the condition number, except by chance. However, a poorly designed algorithm may produce significantly worse results. For example, as mentioned below, the problem of finding eigenvalues for normal matrices is always well-conditioned. However, the problem of finding the roots of a polynomial can be very ill-conditioned. Thus eigenvalue algorithms that work by finding the roots of the characteristic polynomial can be ill-conditioned even when the problem is not.

For the problem of solving the linear equation $x$ where $κ(f, x)$ is invertible, the matrix condition number $Av = b$ is given by $A$, where op  is the operator norm subordinate to the normal Euclidean norm on $κ(A^{−1}, b)$. Since this number is independent of $A_{op}A^{−1}_{op}$ and is the same for $C^{n}$ and $b$, it is usually just called the condition number $A$ of the matrix $A^{−1}$. This value $κ(A)$ is also the absolute value of the ratio of the largest eigenvalue of $A$ to its smallest. If $κ(A)$ is unitary, then $A$, so $A$. For general matrices, the operator norm is often difficult to calculate. For this reason, other matrix norms are commonly used to estimate the condition number.

For the eigenvalue problem, Bauer and Fike proved that if $A_{op} = A^{−1}_{op} = 1$ is an eigenvalue for a diagonalizable $κ(A) = 1$ matrix $λ$ with eigenvector matrix $n × n$, then the absolute error in calculating $A$ is bounded by the product of $V$ and the absolute error in $λ$. As a result, the condition number for finding $κ(V)$ is $A$. If $λ$ is normal, then $κ(λ, A) = κ(V) = V _{op} V ^{−1}_{op}$ is unitary, and $A$. Thus the eigenvalue problem for all normal matrices is well-conditioned.

The condition number for the problem of finding the eigenspace of a normal matrix $V$ corresponding to an eigenvalue $κ(λ, A) = 1$ has been shown to be inversely proportional to the minimum distance between $A$ and the other distinct eigenvalues of $λ$. In particular, the eigenspace problem for normal matrices is well-conditioned for isolated eigenvalues. When eigenvalues are not isolated, the best that can be hoped for is to identify the span of all eigenvectors of nearby eigenvalues.

Algorithms
The most reliable and most widely used algorithm for computing eigenvalues is John G. F. Francis' QR algorithm, considered one of the top ten algorithms of 20th century.

Any monic polynomial is the characteristic polynomial of its companion matrix. Therefore, a general algorithm for finding eigenvalues could also be used to find the roots of polynomials. The Abel–Ruffini theorem shows that any such algorithm for dimensions greater than 4 must either be infinite, or involve functions of greater complexity than elementary arithmetic operations and fractional powers. For this reason algorithms that exactly calculate eigenvalues in a finite number of steps only exist for a few special classes of matrices. For general matrices, algorithms are iterative, producing better approximate solutions with each iteration.

Some algorithms produce every eigenvalue, others will produce a few, or only one. However, even the latter algorithms can be used to find all eigenvalues. Once an eigenvalue $λ$ of a matrix $A$ has been identified, it can be used to either direct the algorithm towards a different solution next time, or to reduce the problem to one that no longer has $λ$ as a solution.

Redirection is usually accomplished by shifting: replacing $A$ with $λ$ for some constant $A$. The eigenvalue found for $A − μI$ must have $μ$ added back in to get an eigenvalue for $A − μI$. For example, for power iteration, $μ$. Power iteration finds the largest eigenvalue in absolute value, so even when $A$ is only an approximate eigenvalue, power iteration is unlikely to find it a second time. Conversely, inverse iteration based methods find the lowest eigenvalue, so $μ = λ$ is chosen well away from $λ$ and hopefully closer to some other eigenvalue.

Reduction can be accomplished by restricting $μ$ to the column space of the matrix $λ$, which $A$ carries to itself. Since $A − λI$ is singular, the column space is of lesser dimension. The eigenvalue algorithm can then be applied to the restricted matrix. This process can be repeated until all eigenvalues are found.

If an eigenvalue algorithm does not produce eigenvectors, a common practice is to use an inverse iteration based algorithm with $A$ set to a close approximation to the eigenvalue. This will quickly converge to the eigenvector of the closest eigenvalue to $A - λI$. For small matrices, an alternative is to look at the column space of the product of $μ$ for each of the other eigenvalues $μ$.

A formula for the norm of unit eigenvector components of normal matrices was discovered by Robert Thompson in 1966 and rediscovered independently by several others. If $A − λ'I$ is an $ n \times n$ normal matrix with eigenvalues $λ'$ and corresponding unit eigenvectors $A$ whose component entries are $λ_{i}(A)$, let $v_{i}$ be the $ n - 1 \times n - 1$  matrix obtained by removing the $v_{i,j}$-th row and column from $A_{j}$, and let $i$ be its $A$-th eigenvalue. Then $$ |v_{i,j}|^2 \prod_{k=1,k\ne i}^n (\lambda_i(A) - \lambda_k(A)) = \prod_{k=1}^{n-1}(\lambda_i(A) - \lambda_k(A_j))$$

If $$p, p_j$$ are the characteristic polynomials of $$A$$ and $$A_j$$, the formula can be re-written as $$ |v_{i,j}|^2 = \frac{p_j(\lambda_i(A))}{p'(\lambda_i(A))}$$ assuming the derivative $$p'$$ is not zero at $$\lambda_i(A)$$.

Hessenberg and tridiagonal matrices
Because the eigenvalues of a triangular matrix are its diagonal elements, for general matrices there is no finite method like gaussian elimination to convert a matrix to triangular form while preserving eigenvalues. But it is possible to reach something close to triangular. An upper Hessenberg matrix is a square matrix for which all entries below the subdiagonal are zero. A lower Hessenberg matrix is one for which all entries above the superdiagonal are zero. Matrices that are both upper and lower Hessenberg are tridiagonal. Hessenberg and tridiagonal matrices are the starting points for many eigenvalue algorithms because the zero entries reduce the complexity of the problem. Several methods are commonly used to convert a general matrix into a Hessenberg matrix with the same eigenvalues. If the original matrix was symmetric or Hermitian, then the resulting matrix will be tridiagonal.

When only eigenvalues are needed, there is no need to calculate the similarity matrix, as the transformed matrix has the same eigenvalues. If eigenvectors are needed as well, the similarity matrix may be needed to transform the eigenvectors of the Hessenberg matrix back into eigenvectors of the original matrix.

For symmetric tridiagonal eigenvalue problems all eigenvalues (without eigenvectors) can be computed numerically in time O(n log(n)), using bisection on the characteristic polynomial.

Iterative algorithms
Iterative algorithms solve the eigenvalue problem by producing sequences that converge to the eigenvalues. Some algorithms also produce sequences of vectors that converge to the eigenvectors. Most commonly, the eigenvalue sequences are expressed as sequences of similar matrices which converge to a triangular or diagonal form, allowing the eigenvalues to be read easily. The eigenvector sequences are expressed as the corresponding similarity matrices.

Direct calculation
While there is no simple algorithm to directly calculate eigenvalues for general matrices, there are numerous special classes of matrices where eigenvalues can be directly calculated. These include:

Triangular matrices
Since the determinant of a triangular matrix is the product of its diagonal entries, if T is triangular, then $\det(\lambda I - T) = \prod_i (\lambda - T_{ii})$. Thus the eigenvalues of T are its diagonal entries.

Factorable polynomial equations
If $λ_{k}(A_{j})$ is any polynomial and $k$ then the eigenvalues of $2n^{3}/3 + O(n^{2})$ also satisfy the same equation. If $4n^{3}/3 + O(n^{2})$ happens to have a known factorization, then the eigenvalues of $4n^{3}/3 + O(n^{2})$ lie among its roots.

For example, a projection is a square matrix $m$ satisfying $O(n^{2})$. The roots of the corresponding scalar polynomial equation, $(A − μI)^{−1}$, are 0 and 1. Thus any projection has 0 and 1 for its eigenvalues. The multiplicity of 0 as an eigenvalue is the nullity of $(A − μ_{i}I)^{−1}$, while the multiplicity of 1 is the rank of $μ_{i}$.

Another example is a matrix $A$ that satisfies $O(n^{2})$ for some scalar $6n^{3} + O(n^{2})$. The eigenvalues must be $O(n^{3})$. The projection operators
 * $$P_+=\frac{1}{2}\left(I+\frac{A}{\alpha}\right)$$


 * $$P_-=\frac{1}{2}\left(I-\frac{A}{\alpha}\right)$$

satisfy
 * $$AP_+=\alpha P_+ \quad AP_-=-\alpha P_-$$

and
 * $$P_+P_+=P_+ \quad P_-P_-=P_- \quad P_+P_-=P_-P_+=0.$$

The column spaces of $O(n^{2})$ and $(4/3)n^{3} + O(n^{2})$ are the eigenspaces of $O(n^{2})$ corresponding to $(A − μI)^{2}$ and $O(n^{2})$, respectively.

2×2 matrices
For dimensions 2 through 4, formulas involving radicals exist that can be used to find the eigenvalues. While a common practice for 2×2 and 3×3 matrices, for 4×4 matrices the increasing complexity of the root formulas makes this approach less attractive.

For the 2×2 matrix


 * $$A = \begin{bmatrix} a & b \\ c & d \end{bmatrix},$$

the characteristic polynomial is


 * $$\det \begin{bmatrix} \lambda - a & -b \\ -c & \lambda - d \end{bmatrix} = \lambda^2\, -\, \left( a + d \right )\lambda\, +\, \left ( ad - bc \right ) = \lambda^2\, -\, \lambda\, {\rm tr}(A)\, +\, \det(A).$$

Thus the eigenvalues can be found by using the quadratic formula:


 * $$\lambda = \frac{{\rm tr}(A) \pm \sqrt{{\rm tr}^2 (A) - 4 \det(A)}}{2}.$$

Defining $ {\rm gap}\left ( A \right ) = \sqrt{{\rm tr}^2 (A) - 4 \det(A)}$  to be the distance between the two eigenvalues, it is straightforward to calculate


 * $$\frac{\partial\lambda}{\partial a} = \frac{1}{2}\left ( 1 \pm \frac{a - d}{{\rm gap}(A)} \right ),\qquad \frac{\partial\lambda}{\partial b} = \frac{\pm c}{{\rm gap}(A)}$$

with similar formulas for $p$ and $p(A) = 0,$. From this it follows that the calculation is well-conditioned if the eigenvalues are isolated.

Eigenvectors can be found by exploiting the Cayley–Hamilton theorem. If $A$ are the eigenvalues, then $p$, so the columns of $A$ are annihilated by $P$ and vice versa. Assuming neither matrix is zero, the columns of each must include eigenvectors for the other eigenvalue. (If either matrix is zero, then $P^{2} = P$ is a multiple of the identity and any non-zero vector is an eigenvector.)

For example, suppose


 * $$A = \begin{bmatrix} 4 & 3 \\ -2 & -3 \end{bmatrix},$$

then $λ^{2} = λ$ and $P$, so the characteristic equation is


 * $$ 0 = \lambda^2 - \lambda - 6 = (\lambda - 3)(\lambda + 2),$$

and the eigenvalues are 3 and -2. Now,


 * $$A - 3I = \begin{bmatrix} 1 & 3 \\ -2 & -6 \end{bmatrix}, \qquad A + 2I = \begin{bmatrix} 6 & 3 \\ -2 & -1 \end{bmatrix}.$$

In both matrices, the columns are multiples of each other, so either column can be used. Thus, $P$ can be taken as an eigenvector associated with the eigenvalue -2, and $A$ as an eigenvector associated with the eigenvalue 3, as can be verified by multiplying them by $A^{2} = α^{2}I$.

Symmetric 3×3 matrices
The characteristic equation of a symmetric 3&times;3 matrix $α$ is:


 * $$\det \left( \alpha I - A \right) = \alpha^3 - \alpha^2 {\rm tr}(A) - \alpha \frac{1}{2}\left( {\rm tr}(A^2) - {\rm tr}^2(A) \right) - \det(A) = 0.$$

This equation may be solved using the methods of Cardano or Lagrange, but an affine change to $±α$ will simplify the expression considerably, and lead directly to a trigonometric solution. If $P_{+}$, then $P_{−}$ and $A$ have the same eigenvectors, and $+α$ is an eigenvalue of $−α$ if and only if $c$ is an eigenvalue of $d$. Letting $ q = {\rm tr}(A)/3$ and $ p =\left({\rm tr}\left((A - qI)^2\right)/ 6\right)^{1/2}$, gives


 * $$\det \left( \beta I - B \right) = \beta^3 - 3 \beta - \det(B) = 0.$$

The substitution $λ_{1}, λ_{2}$ and some simplification using the identity $(A − λ_{1}I)(A − λ_{2}I) = (A − λ_{2}I)(A − λ_{1}I) = 0$ reduces the equation to $(A − λ_{2}I)$. Thus


 * $$\beta = 2{\cos}\left(\frac{1}{3}{\arccos}\left( \det(B)/2 \right) + \frac{2k\pi}{3}\right), \quad k = 0, 1, 2.$$

If $(A − λ_{1}I)$ is complex or is greater than 2 in absolute value, the arccosine should be taken along the same branch for all three values of $A$. This issue doesn't arise when $tr(A) = 4 − 3 = 1$ is real and symmetric, resulting in a simple algorithm:

Once again, the eigenvectors of $det(A) = 4(−3) − 3(−2) = −6$ can be obtained by recourse to the Cayley–Hamilton theorem. If $(1, −2)$ are distinct eigenvalues of $(3, −1)$, then $A$. Thus the columns of the product of any two of these matrices will contain an eigenvector for the third eigenvalue. However, if $A$, then $A$ and $A = pB + qI$. Thus the generalized eigenspace of $A$ is spanned by the columns of $B$ while the ordinary eigenspace is spanned by the columns of $β$. The ordinary eigenspace of $B$ is spanned by the columns of $α = pβ + q$.

For example, let


 * $$A = \begin{bmatrix} 3 & 2 & 6 \\ 2 & 2 & 5 \\ -2 & -1 & -4 \end{bmatrix}.$$

The characteristic equation is


 * $$ 0 = \lambda^3 - \lambda^2 - \lambda + 1 = (\lambda - 1)^2(\lambda + 1),$$

with eigenvalues 1 (of multiplicity 2) and -1. Calculating,


 * $$A - I = \begin{bmatrix} 2 & 2 & 6 \\ 2 & 1 & 5 \\ -2 & -1 & -5 \end{bmatrix}, \qquad A + I = \begin{bmatrix} 4 & 2 & 6 \\ 2 & 3 & 5 \\ -2 & -1 & -3 \end{bmatrix}$$

and


 * $$(A - I)^2 = \begin{bmatrix} -4 & 0 & -8 \\ -4 & 0 & -8 \\ 4 & 0 & 8 \end{bmatrix}, \qquad (A - I)(A + I) = \begin{bmatrix} 0 & 4 & 4 \\ 0 & 2 & 2 \\ 0 & -2 & -2 \end{bmatrix}$$

Thus $A$ is an eigenvector for −1, and $β = 2cos θ$ is an eigenvector for 1. $cos 3θ = 4cos^{3} θ − 3cos θ$ and $cos 3θ = det(B) / 2$ are both generalized eigenvectors associated with 1, either one of which could be combined with $det(B)$ and $k$ to form a basis of generalized eigenvectors of $A$. Once found, the eigenvectors can be normalized if needed.

Eigenvectors of normal 3×3 matrices
If a 3×3 matrix $$A$$ is normal, then the cross-product can be used to find eigenvectors. If $$\lambda$$ is an eigenvalue of $$A$$, then the null space of $$A - \lambda I$$ is perpendicular to its column space. The cross product of two independent columns of $$A - \lambda I$$ will be in the null space. That is, it will be an eigenvector associated with $$\lambda$$. Since the column space is two dimensional in this case, the eigenspace must be one dimensional, so any other eigenvector will be parallel to it.

If $$A - \lambda I$$ does not contain two independent columns but is not $A$, the cross-product can still be used. In this case $$\lambda$$ is an eigenvalue of multiplicity 2, so any vector perpendicular to the column space will be an eigenvector. Suppose $$\mathbf v$$ is a non-zero column of $$A - \lambda I$$. Choose an arbitrary vector $$\mathbf u$$ not parallel to $$\mathbf v$$. Then $$\mathbf v\times \mathbf u$$ and  $$(\mathbf v\times \mathbf u)\times \mathbf v$$ will be perpendicular to $$\mathbf v$$ and thus will be eigenvectors of  $$\lambda$$.

This does not work when $$A$$ is not normal, as the null space and column space do not need to be perpendicular for such matrices.