2x2 Jacobi Algorithm


Finding eigenvalues and eigenvectors of symmetric matrices is pretty useful. Typically you don't have to implement your own algorithms to do this since there are so many packages around that can do it really well. But there are still times you might want to do it yourself, particularly when dealing with small matrices. For 2x2 matrices there's a fast analytic approach, and this can be leveraged to iteratively converge for "larger" matrices. The technique I'm going to use here is called the "Jacobi Algorithm". I used Chapter 3 of Calculus++: The Symmetric Eigenvalue Problem by Eric A Carlen to figure out how to get this working.

for such a matrix I show how eigenvalues \(\mu_+\) and \(\mu_-\) are found,



with the eigenvalues it's easy to find the eigenvectors \(\textbf{u}_0\) and \(\textbf{u}_1\),




finding \(\textbf{v}^\perp\) from \(\textbf{v}\) is straightforward in 2D,




for symmetric matrices all eigenvectors are orthogonal so : \(\textbf{u}_1=\textbf{u}_0^\perp\). With all this we can perform a diagonalization:




Below you can modify some arbitrary \(A\) matrix and see the resulting orthogonal eigenvector matrix \(U\) and the result of \({U}^\intercal AU\), which should be diagonal \(\Lambda\) if \(A={A}^\intercal\).



figure 1 : modify matrix A by typing in entries.


Some practical notes when you implement this. If the off diagonal elements are zero, and the diagonal elements are equal or one is greater than the other, the process outlined above seems to spit out NaN's due to a division by zero. I found an easy way to fix this is to just add some very small value to the off diagonals to ensure they're non-zero. This prevents the division by zero. Technically there's no point even doing anything in this case because your eigenvalues ARE the diagonal entries, however maybe it's advantageous to code this without adding conditional branching for performance reasons on some hardware (GPU implementations?).

Check out 3x3 jacobi algorithm for an example of using the algorithm to iteratively diagonalize in the 3x3 case.



Site Navigation

Homepage