# Jacobi eigenvalue algorithm

## From Wikipedia, the free encyclopedia

In numerical linear algebra, the **Jacobi eigenvalue algorithm** is an iterative method for the calculation of the eigenvalues and eigenvectors of a real symmetric matrix (a process known as diagonalization). It is named after Carl Gustav Jacob Jacobi, who first proposed the method in 1846,^{[1]} but only became widely used in the 1950s with the advent of computers.^{[2]}

## Description

Let be a symmetric matrix, and be a Givens rotation matrix. Then:

is symmetric and similar to .

Furthermore, has entries:

where and .

Since is orthogonal, and have the same Frobenius norm (the square-root sum of squares of all components), however we can choose such that , in which case has a larger sum of squares on the diagonal:

Set this equal to 0, and rearrange:

if

In order to optimize this effect, *S*_{ij} should be the off-diagonal element with the largest absolute value, called the *pivot*.

The Jacobi eigenvalue method repeatedly performs rotations until the matrix becomes almost diagonal. Then the elements in the diagonal are approximations of the (real) eigenvalues of *S*.

## Convergence

If is a pivot element, then by definition for . Let denote the sum of squares of all off-diagonal entries of . Since has exactly off-diagonal elements, we have or . Now . This implies or , i.e. the sequence of Jacobi rotations converges at least linearly by a factor to a diagonal matrix.

A number of Jacobi rotations is called a sweep; let denote the result. The previous estimate yields

- ,

i.e. the sequence of sweeps converges at least linearly with a factor ≈ .

However the following result of Schönhage^{[3]} yields locally quadratic convergence. To this end let *S* have *m* distinct eigenvalues with multiplicities and let *d* > 0 be the smallest distance of two different eigenvalues. Let us call a number of

Jacobi rotations a Schönhage-sweep. If denotes the result then

- .

Thus convergence becomes quadratic as soon as

## Cost

Each Jacobi rotation can be done in O(*n*) steps when the pivot element *p* is known. However the search for *p* requires inspection of all *N* ≈ 1/2 *n*^{2} off-diagonal elements. We can reduce this to O(*n*) complexity too if we introduce an additional index array with the property that is the index of the largest element in row *i*, (*i* = 1, ..., *n* − 1) of the current *S*. Then the indices of the pivot (*k*, *l*) must be one of the pairs . Also the updating of the index array can be done in O(*n*) average-case complexity: First, the maximum entry in the updated rows *k* and *l* can be found in O(*n*) steps. In the other rows *i*, only the entries in columns *k* and *l* change. Looping over these rows, if is neither *k* nor *l*, it suffices to compare the old maximum at to the new entries and update if necessary. If should be equal to *k* or *l* and the corresponding entry decreased during the update, the maximum over row *i* has to be found from scratch in O(*n*) complexity. However, this will happen on average only once per rotation. Thus, each rotation has O(*n*) and one sweep O(*n*^{3}) average-case complexity, which is equivalent to one matrix multiplication. Additionally the must be initialized before the process starts, which can be done in *n*^{2} steps.

Typically the Jacobi method converges within numerical precision after a small number of sweeps. Note that multiple eigenvalues reduce the number of iterations since .

## Algorithm

The following algorithm is a description of the Jacobi method in math-like notation.
It calculates a vector *e* which contains the eigenvalues and a matrix *E* which contains the corresponding eigenvectors, i.e. is an eigenvalue and the column an orthonormal eigenvector for , *i* = 1, ..., *n*.

procedurejacobi(S∈R^{n×n};oute∈R^{n};outE∈R^{n×n})vari,k,l,m,state∈Ns,c,t,p,y,d,r∈Rind∈N^{n}changed∈L^{n}functionmaxind(k∈N) ∈N!index of largest off-diagonal element in row km:=k+1fori:=k+2tondoif│S_{ki}│ > │S_{km}│thenm:=iendifendforreturnmendfuncprocedureupdate(k∈N;t∈R) !update e_{k}and its statusy:=e_{k};e_{k}:=y+tifchanged_{k}and (y=e_{k})thenchanged_{k}:= false;state:=state−1elsif(notchanged_{k}) and (y≠e_{k})thenchanged_{k}:= true;state:=state+1endifendprocprocedurerotate(k,l,i,j∈N) !perform rotation of S┌_{ij}, S_{kl}_{ }┐ ┌ ┐┌_{ }┐ │S_{kl}│ │c−s││S_{kl}│ │_{ }│ := │ ││_{ }│ │S_{ij}│ │sc││S_{ij}│ └_{ }┘ └ ┘└_{ }┘endproc!init e, E, and arrays ind, changedE:=I;state:=nfork:= 1tondoind_{k}:= maxind(k);e_{k}:=S_{kk};changed_{k}:= trueendforwhilestate≠0do!next rotationm:= 1 !find index (k,l) of pivot pfork:= 2ton−1doif│S_{k indk}│ > │S_{m indm}│thenm:=kendifendfork:=m;l:=ind_{m};p:=S_{kl}!calculate c = cos φ, s = sin φy:= (e_{l}−e_{k})/2;d:= │y│+√(p^{2}+y^{2})r:= √(p^{2}+d^{2});c:=d/r;s:=p/r;t:=p^{2}/dify<0thens:= −s;t:= −tendifS_{kl}:= 0.0; update(k,−t); update(l,t) !rotate rows and columns k and lfori:= 1tok−1dorotate(i,k,i,l)endforfori:=k+1tol−1dorotate(k,i,i,l)endforfori:=l+1tondorotate(k,i,l,i)endfor!rotate eigenvectorsfori:= 1tondo┌_{ }┐ ┌ ┐┌_{ }┐ │E_{ik}│ │c−s││E_{ik}│ │_{ }│ := │ ││_{ }│ │E_{il}│ │sc││E_{il}│ └_{ }┘ └ ┘└_{ }┘endfor!rows k, l have changed, update rows ind_{k}, ind_{l}ind_{k}:= maxind(k);ind_{l}:= maxind(l)loopendproc

### Notes

1. The logical array *changed* holds the status of each eigenvalue. If the numerical value of or changes during an iteration, the corresponding component of *changed* is set to *true*, otherwise to *false*. The integer *state* counts the number of components of *changed* which have the value *true*. Iteration stops as soon as *state* = 0. This means that none of the approximations has recently changed its value and thus it is not very likely that this will happen if iteration continues. Here it is assumed that floating point operations are optimally rounded to the nearest floating point number.

2. The upper triangle of the matrix *S* is destroyed while the lower triangle and the diagonal are unchanged. Thus it is possible to restore *S* if necessary according to

fork:= 1ton−1do!restore matrix Sforl:=k+1tondoS_{kl}:=S_{lk}endforendfor

3. The eigenvalues are not necessarily in descending order. This can be achieved by a simple sorting algorithm.

fork:= 1ton−1dom:=kforl:=k+1tondoife_{l}>e_{m}thenm:=lendifendforifk≠mthenswape_{m},e_{k}swapE_{m},E_{k}endifendfor

4. The algorithm is written using matrix notation (1 based arrays instead of 0 based).

5. When implementing the algorithm, the part specified using matrix notation must be performed simultaneously.

6. This implementation does not correctly account for the case in which one dimension is an independent subspace. For example, if given a diagonal matrix, the above implementation will never terminate, as none of the eigenvalues will change. Hence, in real implementations, extra logic must be added to account for this case.

### Example

Let

Then *jacobi* produces the following eigenvalues and eigenvectors after 3 sweeps (19 iterations) :

## Applications for real symmetric matrices

When the eigenvalues (and eigenvectors) of a symmetric matrix are known, the following values are easily calculated.

- Singular values
- The singular values of a (square) matrix
*A*are the square roots of the (non-negative) eigenvalues of . In case of a symmetric matrix*S*we have of , hence the singular values of*S*are the absolute values of the eigenvalues of*S*

- 2-norm and spectral radius
- The 2-norm of a matrix
*A*is the norm based on the Euclidean vectornorm, i.e. the largest value when x runs through all vectors with . It is the largest singular value of*A*. In case of a symmetric matrix it is the largest absolute value of its eigenvectors and thus equal to its spectral radius.

- Condition number
- The condition number of a nonsingular matrix
*A*is defined as . In case of a symmetric matrix it is the absolute value of the quotient of the largest and smallest eigenvalue. Matrices with large condition numbers can cause numerically unstable results: small perturbation can result in large errors. Hilbert matrices are the most famous ill-conditioned matrices. For example, the fourth-order Hilbert matrix has a condition of 15514, while for order 8 it is 2.7 × 10^{8}.

- Rank
- A matrix
*A*has rank*r*if it has*r*columns that are linearly independent while the remaining columns are linearly dependent on these. Equivalently,*r*is the dimension of the range of*A*. Furthermore it is the number of nonzero singular values. - In case of a symmetric matrix r is the number of nonzero eigenvalues. Unfortunately because of rounding errors numerical approximations of zero eigenvalues may not be zero (it may also happen that a numerical approximation is zero while the true value is not). Thus one can only calculate the
*numerical*rank by making a decision which of the eigenvalues are close enough to zero.

- Pseudo-inverse
- The pseudo inverse of a matrix
*A*is the unique matrix for which*AX*and*XA*are symmetric and for which*AXA = A, XAX = X*holds. If*A*is nonsingular, then '. - When procedure jacobi (S, e, E) is called, then the relation holds where Diag(
*e*) denotes the diagonal matrix with vector*e*on the diagonal. Let denote the vector where is replaced by if and by 0 if is (numerically close to) zero. Since matrix*E*is orthogonal, it follows that the pseudo-inverse of S is given by .

- Least squares solution
- If matrix
*A*does not have full rank, there may not be a solution of the linear system*Ax = b*. However one can look for a vector x for which is minimal. The solution is . In case of a symmetric matrix*S*as before, one has .

- Matrix exponential
- From one finds where exp
*e*is the vector where is replaced by . In the same way,*f*(*S*) can be calculated in an obvious way for any (analytic) function*f*.

- Linear differential equations
- The differential equation
*x'*=*Ax*,*x*(0) =*a*has the solution*x*(*t*) = exp(*t A*)*a*. For a symmetric matrix*S*, it follows that . If is the expansion of*a*by the eigenvectors of*S*, then . - Let be the vector space spanned by the eigenvectors of
*S*which correspond to a negative eigenvalue and analogously for the positive eigenvalues. If then i.e. the equilibrium point 0 is attractive to*x*(*t*). If then , i.e. 0 is repulsive to*x*(*t*). and are called*stable*and*unstable*manifolds for*S*. If*a*has components in both manifolds, then one component is attracted and one component is repelled. Hence*x*(*t*) approaches as .

## Generalizations

The Jacobi Method has been generalized to complex Hermitian matrices, general nonsymmetric real and complex matrices as well as block matrices.

Since singular values of a real matrix are the square roots of the eigenvalues of the symmetric matrix it can also be used for the calculation of these values. For this case, the method is modified in such a way that *S* must not be explicitly calculated which reduces the danger of round-off errors. Note that with .

The Jacobi Method is also well suited for parallelism.

Text is available under the CC BY-SA 4.0 license; additional terms may apply.

Images, videos and audio are available under their respective licenses.