Computing Eigenvalues and Singular Values


Computing Eigenvalues and Singular Values

Maria
Today we're focusing on how numerical methods compute eigenvalues and singular values. The main surprise is that the QR factorization, which may have seemed like a tool for solving other linear algebra problems, is actually at the heart of the eigenvalue algorithm.

Corey
And this is not meant to be a full course in numerical linear algebra. The goal is to understand the central ideas behind the commands we use in MATLAB, Python, or Julia, such as eig and SVD.

Maria
Let's begin with eigenvalues. Start with a matrix A, which we'll call A0, and factor it as A0 equals Q0R0. Here Q0 has orthonormal columns, while R0 is upper triangular. In other words, QR factorization replaces the original, generally nonorthogonal columns with an orthogonal basis and records the connection between the two bases in R0.

Corey
Then comes the key move: reverse the order of the factors. Define A1 to be R0Q0 instead of Q0R0. We repeat the process: factor A1 as Q1R1, reverse the factors to obtain A2, and continue.

Maria
The first question is whether this process preserves the eigenvalues. It does, because A1 is similar to A0. From A0 equals Q0R0, we get Q0 equals A0R0 inverse. Therefore A1 equals R0Q0 equals R0A0R0 inverse, which is a similarity transformation of A0.

Corey
That distinction matters. We would not compute all the eigenvalues of A0 and A1 separately just to compare them. The standard test is to show that the matrices are similar, because similar matrices have the same eigenvalues.

Maria
The second idea is the remarkable convergence behavior. As the QR steps continue, entries below the main diagonal generally become smaller and smaller. Once those entries are tiny, the matrix is nearly triangular, and its diagonal entries are close to the eigenvalues because every matrix in the sequence has the same eigenvalues.

Corey
So the diagonal gradually reveals the eigenvalues, even though we never explicitly solve the characteristic polynomial. The entries that are still small are often represented by epsilon, meaning that their effect on the eigenvalues is small.

Maria
A two-by-two example illustrates how fast this can be. In the example discussed, an off-diagonal entry involving sine of an angle becomes sine cubed of that angle after one QR step. The next steps produce the ninth power, then the twenty-seventh power. That rapid decrease is called cubic convergence in this example.

Corey
That explains why the QR method quickly displaced many older eigenvalue algorithms. But numerical analysts still looked for ways to make it faster, and the major improvement was to introduce a shift.

Maria
A shift means choosing a scalar s and working with A0 minus sI. If A0v equals lambda v, then multiplying the shifted matrix by v gives A0v minus sIv, which equals lambda v minus sv, or lambda minus s times v. So the eigenvectors stay the same, while every eigenvalue is shifted by s.

Corey
The practical idea is to choose s near an eigenvalue we want to find. Then that eigenvalue is moved close to zero in the shifted matrix, and the QR process can converge much faster toward it.

Maria
The shifted step follows the same pattern. Factor A0 minus sI as Q0R0, reverse the factors to form R0Q0, and then add sI back. In symbols, the new matrix is A1 equals R0Q0 plus sI.

Corey
And adding and subtracting the shift does not destroy similarity. Since Q0 equals A0 minus sI times R0 inverse, substituting into R0Q0 plus sI gives R0 times A0 minus sI times R0 inverse, plus sI. The minus sI term becomes minus sI after the factors cancel, so it cancels the final plus sI, leaving R0A0R0 inverse.

Maria
Thus the shifted QR method still produces a matrix similar to the original one, so the eigenvalues are preserved. The shift costs very little computationally; the significant work remains the QR factorization at every step.

Corey
That leads to the next improvement: reduce the amount of work in each QR factorization by creating zeros before the iteration begins. A general matrix cannot usually be reduced all the way to triangular form by simple operations while preserving the eigenvalue problem.

Maria
There is a fundamental reason for that limitation. Eigenvalues satisfy a polynomial equation of degree n, and for degree five and higher there is no general simple formula using the usual arithmetic operations and radicals. So exact formulas for arbitrary eigenvalues are not available in the way that triangularization solves a system exactly.

Corey
But we can still approximate eigenvalues as accurately as we like by continuing the QR iteration. Before doing that, we can use a similarity transformation to reduce A to upper Hessenberg form.

Maria
An upper Hessenberg matrix has zeros below the first subdiagonal. It is almost upper triangular, but one extra diagonal remains. These zeros are valuable because they are preserved during the QR steps, allowing the factorization to skip many operations and reducing the work substantially.

Corey
So the full practical eigenvalue algorithm has two stages. First, use a similarity transformation to reduce the original matrix to upper Hessenberg form. Second, apply shifted QR iterations to that Hessenberg matrix.

Maria
That is the kind of procedure hidden behind an eigenvalue command such as eig. Software packages such as MATLAB rely on highly developed numerical linear algebra libraries, especially LAPACK, whose routines were written and analyzed by teams of professional numerical analysts.

Corey
Symmetry makes the problem even easier. If A0 is symmetric, the QR iteration can be shown to preserve symmetry. A symmetric upper Hessenberg matrix has nonzero entries only on the main diagonal and the first diagonal above and below it.

Maria
That structure is called a symmetric tridiagonal matrix. Because the upper and lower off-diagonal entries are mirror images, it contains only about two n independent numbers rather than on the order of n squared. The QR iteration stays tridiagonal, so eigenvalue computations for symmetric matrices become especially efficient.

Corey
Now let's turn to singular values. Mathematically, the singular values of A are the square roots of the eigenvalues of A transpose A. But we should not form A transpose A as the computational method.

Maria
Forming A transpose A can lose numerical information and worsen conditioning. Similarly, directly solving a characteristic equation with a determinant is a poor computational strategy: it is extremely slow, compresses a large amount of information into a small set of coefficients, and is very ill-conditioned.

Corey
The better approach again uses orthogonal transformations. For eigenvalues, similarity transformations have the form Q A Q inverse and preserve the eigenvalues. For singular values, we have more freedom: we can multiply on the left and right by different orthogonal matrices.

Maria
To see why, write the singular value decomposition as A equals U Sigma V transpose, where U and V are orthogonal and Sigma contains the singular values on its diagonal. If we multiply A on the left by an orthogonal matrix Q1 and on the right by another orthogonal matrix Q2 transpose, the new matrix is Q1U Sigma V transpose Q2 transpose.

Corey
The products Q1U and Q2V are still orthogonal, because the product of orthogonal matrices is orthogonal. Therefore the same diagonal matrix Sigma remains in the middle, so the singular values do not change.

Maria
This extra freedom lets us reduce a general matrix further than the eigenvalue problem allows. Using different orthogonal transformations on the left and right, we can reduce A to bidiagonal form, with nonzero entries only on the main diagonal and one adjacent diagonal.

Corey
Once the matrix is bidiagonal, its transpose times itself is tridiagonal. So the singular-value problem connects directly to the efficient symmetric tridiagonal eigenvalue problem, without explicitly forming A transpose A.

Maria
The SVD algorithm therefore also has two broad stages. First, use orthogonal transformations to reduce A to bidiagonal form while preserving its singular values. Second, apply an iterative method, related to the QR idea, to compute those values efficiently.

Corey
For matrices of moderate size, these methods are a major success. They obtain eigenvalues or singular values to within a chosen tolerance, with work described as roughly proportional to n cubed. The computation is not an exact finite formula; it is an efficient approximation process.

Maria
But when the matrix becomes extremely large, even a cubic-time method may be too expensive. That is where the Krylov idea becomes useful, especially for sparse matrices.

Corey
Krylov methods begin with a vector b and generate b, Ab, A squared b, and so on. These vectors span a Krylov subspace. Instead of studying the full matrix, perhaps of size one million by one million, we study how the matrix acts on a much smaller subspace, such as one of dimension one hundred.

Maria
A vector in that subspace can be written as a combination of b, Ab, through A to the ninety-ninth power times b, with a possible error from components outside the subspace. The method ignores that outside component and represents the action of A using a one-hundred-by-one-hundred problem.

Corey
The basis vectors are orthogonalized, again using Gram-Schmidt or a related process. If the relevant eigenvectors are well captured by the Krylov subspace, the smaller problem gives accurate approximations to some of the large matrix's eigenvalues, although it is not automatically guaranteed to produce exactly the lowest one hundred.

Maria
So the main lessons are these: similarity preserves eigenvalues, shifted QR accelerates convergence, Hessenberg form makes QR cheaper, and symmetry reduces Hessenberg form to tridiagonal form. For singular values, independent orthogonal transformations on the left and right preserve the values and allow reduction to bidiagonal form.

Corey
And for very large problems, especially sparse ones, Krylov subspaces replace the full matrix problem with a smaller projected problem. The broader principle is to preserve the quantities we want while transforming the matrix into a structured form where computation is fast.

Maria
That principle also explains why random sampling is an interesting next direction for matrices that are simply too large to process directly. Instead of handling every entry, one asks whether a carefully chosen sample can still capture the information needed for a useful answer.

Corey
For this episode, though, the essential computational story is the QR and SVD framework: transform first to expose zeros and structure, then iterate on the smaller structured matrix until the desired eigenvalues or singular values emerge to the required accuracy.

Ask anything
We've read this whole study set, so questions about it get the best answers.