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 sameConvergence
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 ; that is, the sequence of Jacobi rotations converges at least linearly by a factor to aCost
Each Givens rotation can be done in steps when the pivot element ''p'' is known. However the search for ''p'' requires inspection of all ''N'' ≈ ''n''2 off-diagonal elements, which means this search dominates the overall complexity and pushes the computational complexity of a sweep in the classical Jacobi algorithm to . Competing algorithms attain complexity for a full diagonalisation.Caching row maximums
We can reduce the complexity of finding the pivot element from O(''N'') to O(''n'') 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 .Cyclic and parallel Jacobi
An alternative approach is to forego the search entirely, and simply have each sweep pivot every off-diagonal element once, in some predetermined order. It has been shown that this ''cyclic Jacobi'' attains quadratic convergence, just like the classical Jacobi. The opportunity for parallelisation that is particular to Jacobi is based on combining cyclic Jacobi with the observation that Givens rotations forAlgorithm
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; that is, is an eigenvalue and the column an orthonormal eigenvector for , ''i'' = 1, ..., ''n''. procedure jacobi(''S'' ∈ R''n''×''n''; out ''e'' ∈ R''n''; out ''E'' ∈ R''n''×''n'') var ''i'', ''k'', ''l'', ''m'', ''state'' ∈ N ''s'', ''c'', ''t'', ''p'', ''y'', ''d'', ''r'' ∈ R ''ind'' ∈ N''n'' ''changed'' ∈ L''n'' function maxind(''k'' ∈ N) ∈ N ! ''index of largest off-diagonal element in row k'' ''m'' := ''k''+1 for ''i'' := ''k''+2 to ''n'' do if │''S''''ki''│ > │''S''''km''│ then ''m'' := ''i'' endif endfor return ''m'' endfunc procedure update(''k'' ∈ N; ''t'' ∈ R) ! ''update ek and its status'' ''y'' := ''e''''k''; ''e''''k'' := ''y''+''t'' if ''changed''''k'' and (''y''=''e''''k'') then ''changed''''k'' := false; ''state'' := ''state''−1 elsif (not ''changed''''k'') and (''y''≠''e''''k'') then ''changed''''k'' := true; ''state'' := ''state''+1 endif endproc procedure rotate(''k'',''l'',''i'',''j'' ∈ N) ! ''perform rotation of Sij, Skl'' ┌ ┐ ┌ ┐┌ ┐ │''S''''kl''│ │''c'' −''s''││''S''''kl''│ │ │ := │ ││ │ │''S''''ij''│ │''s'' ''c''││''S''''ij''│ └ ┘ └ ┘└ ┘ endproc ! ''init e, E, and arrays ind, changed'' ''E'' := ''I''; ''state'' := ''n'' for ''k'' := 1 to ''n'' do ''ind''''k'' := maxind(''k''); ''e''''k'' := ''S''''kk''; ''changed''''k'' := true endfor while ''state''≠0 do ! ''next rotation'' ''m'' := 1 ! ''find index (k,l) of pivot p'' for ''k'' := 2 to ''n''−1 do if │''S''''k'' ''ind''''k''│ > │''S''''m'' ''ind''''m''│ then ''m'' := ''k'' endif endfor ''k'' := ''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/''d'' if ''y''<0 then ''s'' := −''s''; ''t'' := −''t'' endif ''S''''kl'' := 0.0; update(''k'',−''t''); update(''l'',''t'') ! ''rotate rows and columns k and l for ''i'' := 1 to ''k''−1 do rotate(''i'',''k'',''i'',''l'') endfor for ''i'' := ''k''+1 to ''l''−1 do rotate(''k'',''i'',''i'',''l'') endfor for ''i'' := ''l''+1 to ''n'' do rotate(''k'',''i'',''l'',''i'') endfor ! ''rotate eigenvectors'' for ''i'' := 1 to ''n'' do ┌ ┐ ┌ ┐┌ ┐ │''E''''ik''│ │''c'' −''s''││''E''''ik''│ │ │ := │ ││ │ │''E''''il''│ │''s'' ''c''││''E''''il''│ └ ┘ └ ┘└ ┘ endfor ! ''update all potentially changed indi'' for ''i'' := 1 to ''n'' do ''ind''''i'' := maxind(''i'') endfor loop endprocNotes
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 for ''k'' := 1 to ''n''−1 do ! ''restore matrix S'' for ''l'' := ''k''+1 to ''n'' do ''S''''kl'' := ''S''''lk'' endfor endfor 3. The eigenvalues are not necessarily in descending order. This can be achieved by a simple sorting algorithm. for ''k'' := 1 to ''n''−1 do ''m'' := ''k'' for ''l'' := ''k''+1 to ''n'' do if ''e''''l'' > ''e''''m'' then ''m'' := ''l'' endif endfor if ''k'' ≠ ''m'' then swap ''e''''m'',''e''''k'' swap ''E''''m'',''E''''k'' endif endfor 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 are the square roots of the (non-negative) eigenvalues of . In case of a symmetric matrix we have of , hence the singular values of are the absolute values of the eigenvalues of . ;2-norm and spectral radius :The 2-norm of a matrix ''A'' is the norm based on the Euclidean vectornorm; that is, the largest value when x runs through all vectors with . It is the largest singular value of . 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 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 × 108. ;Rank :A matrix has rank if it has columns that are linearly independent while the remaining columns are linearly dependent on these. Equivalently, is the dimension of the range of . 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 is the unique matrix for which and are symmetric and for which holds. If 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 does not have full rank, there may not be a solution of the linear system . 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 is the vector where is replaced by . In the same way, can be calculated in an obvious way for any (analytic) function . ;Linear differential equations :The differential equation has the solution . For a symmetric matrix , it follows that . If is the expansion of by the eigenvectors of , then . :Let be the vector space spanned by the eigenvectors of which correspond to a negative eigenvalue and analogously for the positive eigenvalues. If then ; that is, the equilibrium point 0 is attractive to . If then ; that is, 0 is repulsive to . and are called ''stable'' and ''unstable'' manifolds for . If has components in both manifolds, then one component is attracted and one component is repelled. Hence approaches as .Julia implementation
The following code is a straight-forward implementation of the mathematical description of the Jacobi eigenvalue algorithm in the Julia programming language.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 ofReferences
Further reading
* * * * * * * Yousef Saad: "Revisiting the (block) Jacobi subspace rotation method for the symmetric eigenvalue problem", Numerical Algorithms, vol.92 (2023), pp.917-944. https://doi.org/10.1007/s11075-022-01377-w .External links