Computing Library › Numerical Methods
Numerical Methods

The QR Algorithm

The QR algorithm computes all eigenvalues of a matrix by repeated QR factorization, accelerated by Hessenberg reduction and shifts.

Iterating with orthogonal factorizations

The QR algorithm is the standard method for the full eigenvalue spectrum of a dense matrix. It factors the matrix as A = Q R, with Q orthogonal and R upper triangular, then forms the next iterate A' = R Q. This similarity transformation preserves eigenvalues while driving the matrix toward upper-triangular (Schur) form, exposing the eigenvalues on the diagonal.

Why it converges

Each QR step is implicitly related to power iteration on all invariant subspaces at once. Off-diagonal entries shrink geometrically at rates set by ratios of eigenvalues. Left alone this can be slow, so the practical algorithm adds two accelerations that make it fast and reliable.

Hessenberg reduction and shifts

python
import numpy as np
def qr_algorithm(A, iters=500):
    Ak = A.astype(float).copy()
    for _ in range(iters):
        Q, R = np.linalg.qr(Ak)
        Ak = R @ Q
    return np.diag(Ak)   # eigenvalues (real symmetric case)

Reliability

The shifted QR algorithm with Hessenberg reduction is backward stable and is the engine behind eig routines in LAPACK and every major numerical library. For symmetric matrices it specializes to a tridiagonal QR that is especially fast and accurate. For very large sparse matrices, Krylov methods replace it since forming dense Q is infeasible.

Dense eigen-solvers of this kind analyze mode structure in reduced models supporting breeder Hyperion stability studies.