Foundations to Frontier
Tests
A. Mathematical Foundations › A2 Linear Algebra › Advanced linear algebra

Krylov Subspace Methods: Lanczos, Arnoldi and Conjugate Gradients

When a matrix is too big to store, or exists only as a function you can call, you can still solve systems and find eigenvalues by repeatedly multiplying vectors by it. Krylov methods power large-scale simulation, Gaussian processes, Hessian-free optimization and the trust-region steps of robot-learning algorithms.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Learning a machine by poking it

Imagine a huge machine you can’t open. All you can do is put something in and see what comes out. If you feed the output back in again and again, you collect a few clues: b\mathbf b, then AbA\mathbf b, then A2bA^2\mathbf b. These clues span a Krylov subspace.

The surprise is that a few dozen clues are often enough to solve equations with millions of unknowns, or to find a machine’s strongest and weakest directions.

Walking down a narrow valley shows why the smart way matters. Steepest descent zig-zags from wall to wall. Conjugate gradients remembers where it has been and heads straight for the bottom.

Conjugate gradients vs steepest descent
1e-01e-41e-81e-12iteration 080
green = steepest descent (33 zig-zag steps shown in 2-D) · orange = CG (exactly 2 steps in 2-D) · after 80 steps on 60-D: steepest descent error 2.4e-5, CG 1.0e-12
Steepest descent always turns 90° and zig-zags across a narrow valley; its error shrinks by about (κ−1)/(κ+1) per step. CG remembers previous directions (A-conjugacy), so it shrinks by about (√κ−1)/(√κ+1) and finishes in n steps exactly. Right panel: A-norm error on a log scale.
Why engineers care

A spacecraft’s structural model can have millions of unknowns, far too many to store as a full matrix. Engineers find its vibration modes and solve its stress equations with Krylov methods, which only ever ask the model “what happens if I push this way?”.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Krylov methods only need to…
  2. 2. In a narrow valley, steepest descent…
  3. 3. After feeding the output back 3 times, how many clue vectors do you have (b, Ab, A²b, A³b)?

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

The Krylov subspace

Kk(A,b)=span⁡{b,Ab,A2b,…,Ak−1b}\mathcal K_k(A,\mathbf b) = \operatorname{span}\{\mathbf b, A\mathbf b, A^2\mathbf b,\dots,A^{k-1}\mathbf b\}
  • Only matrix–vector products are needed. That’s perfect for sparse matrices: a 2-D grid simulation with n=106n = 10^6 unknowns has only about 5 nonzeros per row, so a product costs about 5×1065\times10^6 operations, while the dense matrix would need 101210^{12} numbers.
  • It also works for matrix-free operators: Hessian–vector products in deep learning, or “run the simulator once”.
  • Each step adds one dimension (until the space stops growing). Any vector in Kk\mathcal K_k is p(A)bp(A)\mathbf b for a polynomial pp of degree <k< k.

Example. A=diag⁡(1,2)A = \operatorname{diag}(1,2), b=(1,1)\mathbf b = (1,1): Ab=(1,2)A\mathbf b = (1,2), A2b=(1,4)A^2\mathbf b = (1,4).

📝 Quick check (Level 1)
0/3 answered
  1. 1. For A = diag(1, 2), b = (1, 1): A²b = ?
  2. 2. If b is an eigenvector of A, the Krylov space has dimension…
  3. 3. Why are Krylov methods great for sparse matrices?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

Arnoldi and Lanczos: an orthonormal basis for Kk\mathcal K_k

The raw vectors AjbA^j\mathbf b quickly line up with the top eigenvector, so they form a terrible basis (power iteration, A2.3-1). Arnoldi runs Gram–Schmidt (A2.4-1) as it goes: multiply the newest basis vector by AA, then orthogonalize. This gives

AQk=Qk+1H~k,Hk=Qk⊤AQk (upper Hessenberg)AQ_k = Q_{k+1}\tilde H_k, \qquad H_k = Q_k^\top AQ_k \ \text{(upper Hessenberg)}

For symmetric AA, HkH_k is symmetric and Hessenberg, so it is tridiagonal. Each new vector only needs the previous two: that’s the Lanczos three-term recurrence. The eigenvalues of the small matrix HkH_k (the Ritz values) approximate the extreme eigenvalues of AA remarkably fast.

Conjugate gradients (CG)

For symmetric positive-definite AA, solving Ax=bA\mathbf x = \mathbf b is the same as minimizing f(x)=12x⊤Ax−b⊤xf(\mathbf x) = \tfrac12\mathbf x^\top A\mathbf x - \mathbf b^\top\mathbf x. CG (Hestenes and Stiefel, 1952) picks xk\mathbf x_k as the best point in x0+Kk\mathbf x_0 + \mathcal K_k in the AA-norm, using short recurrences:

αk=rk⊤rkpk⊤Apk,xk+1=xk+αkpk,rk+1=rk−αkApk,pk+1=rk+1+rk+1⊤rk+1rk⊤rkpk\alpha_k = \frac{\mathbf r_k^\top\mathbf r_k}{\mathbf p_k^\top A\mathbf p_k}, \quad \mathbf x_{k+1} = \mathbf x_k + \alpha_k\mathbf p_k, \quad \mathbf r_{k+1} = \mathbf r_k - \alpha_kA\mathbf p_k, \quad \mathbf p_{k+1} = \mathbf r_{k+1} + \frac{\mathbf r_{k+1}^\top\mathbf r_{k+1}}{\mathbf r_k^\top\mathbf r_k}\mathbf p_k

The search directions are A-conjugate (pi⊤Apj=0\mathbf p_i^\top A\mathbf p_j = 0), so progress along one is never undone by the next.

Method Matrix Minimizes over x0+Kk\mathbf x_0 + \mathcal K_k Iterations to accuracy ε
steepest descent SPD (one direction only) O(κlog⁡1ε)O(\kappa\log\frac1\varepsilon)
CG SPD the AA-norm error O(κlog⁡1ε)O(\sqrt\kappa\log\frac1\varepsilon)
MINRES symmetric the residual norm similar
GMRES any the residual norm depends on the spectrum and non-normality

Preconditioning solves M−1Ax=M−1bM^{-1}A\mathbf x = M^{-1}\mathbf b with M≈AM\approx A cheap to invert (Jacobi, incomplete Cholesky, multigrid). It shrinks κ\kappa, and with it the number of iterations.

🐍 Exercise 1: CG vs gradient descent
Implement CG and optimal-step gradient descent. On 200 × 200 SPD systems with κ = 100 and 2,500, compare the iteration counts and how they grow with κ.
📝 Quick check (Level 2)
0/3 answered
  1. 1. CG needs roughly how many iterations for κ = 10⁴?
  2. 2. For symmetric A, the Arnoldi matrix H is…
  3. 3. GMRES minimizes…

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

The polynomial view

Every Krylov iterate is xk=x0+q(A)r0\mathbf x_k = \mathbf x_0 + q(A)\mathbf r_0, so its error is ek=pk(A)e0\mathbf e_k = p_k(A)\mathbf e_0 for a polynomial pkp_k of degree kk with pk(0)=1p_k(0) = 1. CG’s optimality gives

∥ek∥A∥e0∥A≤min⁡pk(0)=1 max⁡λ∈σ(A)∣pk(λ)∣\frac{\lVert\mathbf e_k\rVert_A}{\lVert\mathbf e_0\rVert_A}\le\min_{p_k(0)=1}\ \max_{\lambda\in\sigma(A)}\lvert p_k(\lambda)\rvert

Two consequences:

  1. Finite termination. If AA has dd distinct eigenvalues, take p(λ)=∏i(1−λ/λi)p(\lambda) = \prod_i(1 - \lambda/\lambda_i), which is zero on the whole spectrum. So CG is exact in d≤nd\le n steps (in exact arithmetic).
  2. The Chebyshev bound. Choosing the shifted Chebyshev polynomial on [λmin⁡,λmax⁡][\lambda_{\min},\lambda_{\max}] gives
∥ek∥A∥e0∥A≤2(κ−1κ+1)k\frac{\lVert\mathbf e_k\rVert_A}{\lVert\mathbf e_0\rVert_A}\le2\Big(\frac{\sqrt\kappa - 1}{\sqrt\kappa + 1}\Big)^k

Clustered eigenvalues make CG even faster than this bound. That is the real goal of a preconditioner.

Lanczos in floating point

In exact arithmetic, Lanczos vectors stay orthogonal. In floating point, they lose orthogonality exactly when a Ritz value converges. Paige (1971) showed this loss is structured, not random. The symptom is “ghost” duplicate eigenvalues. Remedies are full or selective reorthogonalization, or implicit restarts (ARPACK, Lehoucq, Sorensen and Yang, 1998). Despite this, CG and Lanczos remain the methods of choice, and their finite-precision behaviour is well understood (Greenbaum, 1997).

Exercise 3.1: Why is the A-norm error of CG monotonically decreasing?

The spaces are nested: Kk⊆Kk+1\mathcal K_k\subseteq\mathcal K_{k+1}. CG returns the A-norm-optimal point in each, and minimizing over a bigger space can’t do worse.

📝 Quick check (Level 3)
0/3 answered
  1. 1. A has 4 distinct eigenvalues. CG (exact arithmetic) finishes in at most…
  2. 2. The Chebyshev factor (√κ−1)/(√κ+1) for κ = 100?
  3. 3. Plain Lanczos in floating point loses…

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

Eigenvalues of operators you never form

🐍 Exercise 2 (research): Lanczos on a 1600 × 1600 operator
Implement Lanczos (with reorthogonalization) using only a function that applies the 2-D grid Laplacian. Find its smallest and largest eigenvalues to 10⁻⁶ in 150 products, and compare with the exact formula.

Krylov methods in ML, robotics and space

  • Hessian-free optimization. Solve the Newton system Hd=−gH\mathbf d = -\mathbf g with CG, using Hessian–vector products. Pearlmutter’s trick computes them for about the cost of a gradient (Martens, 2010).
  • Trust-region policy optimization (TRPO). Robot-learning agents solve Fx=gF\mathbf x = \mathbf g (with FF the Fisher matrix) by about 10 CG iterations of Fisher–vector products to get the natural-gradient step (Schulman et al., 2015). This is how locomotion policies for simulated legged robots were trained.
  • Loss-landscape spectra. Lanczos on Hessian–vector products gives the top eigenvalues (sharpness, A2.4-2) and, via stochastic Lanczos quadrature, the full spectral density of networks with millions of parameters (Ghorbani, Krishnan and Xiao, 2019).
  • Gaussian processes at scale. GPyTorch replaces Cholesky (O(n3)O(n^3)) with batched preconditioned CG, plus Lanczos for log-determinants (Gardner et al., 2018). Exact GPs on a million points became feasible.
  • Structural and fluid simulation. Finite-element models of spacecraft and aircraft are solved with preconditioned CG/GMRES (often with multigrid), and their vibration modes are found with ARPACK’s implicitly restarted Arnoldi/Lanczos. This is the same software behind scipy.sparse.linalg.eigsh.
  • PageRank and graphs: power and Arnoldi iterations on web-scale sparse matrices.

References

  1. C. Lanczos (1950). “An iteration method for the solution of the eigenvalue problem of linear differential and integral operators.” J. Res. Nat. Bur. Standards, 45.
  2. W. Arnoldi (1951). “The principle of minimized iterations in the solution of the matrix eigenvalue problem.” Quarterly of Applied Mathematics, 9.
  3. M. Hestenes, E. Stiefel (1952). “Methods of conjugate gradients for solving linear systems.” J. Res. Nat. Bur. Standards, 49(6).
  4. C. Paige (1971). The computation of eigenvalues and eigenvectors of very large sparse matrices. PhD thesis, University of London.
  5. Y. Saad, M. Schultz (1986). “GMRES: A generalized minimal residual algorithm for solving nonsymmetric linear systems.” SIAM J. Sci. Stat. Comput., 7(3).
  6. A. Greenbaum (1997). Iterative Methods for Solving Linear Systems. SIAM.
  7. R. Lehoucq, D. Sorensen, C. Yang (1998). ARPACK Users’ Guide. SIAM.
  8. J. Martens (2010). “Deep learning via Hessian-free optimization.” ICML.
  9. J. Schulman, S. Levine, P. Moritz, M. Jordan, P. Abbeel (2015). “Trust region policy optimization.” ICML.
  10. J. Gardner, G. Pleiss, D. Bindel, K. Weinberger, A. G. Wilson (2018). “GPyTorch: Blackbox matrix-matrix Gaussian process inference with GPU acceleration.” NeurIPS.
  11. B. Ghorbani, S. Krishnan, Y. Xiao (2019). “An investigation into neural net optimization via Hessian eigenvalue density.” ICML.