- Introduced by
- Magnus Hestenes and Eduard Stiefel
- Year
- 1952
- Type
- Iterative linear solver
- Family
- Krylov Subspace Iterative
What does it do?
The Conjugate Gradient (CG) method is an iterative algorithm for solving linear systems Ax = b in which A is symmetric positive-definite; Hestenes and Stiefel introduced it in 1952.
In exact arithmetic it terminates in at most n steps for an n × n matrix, but in practice it is used as an iterative method that stops once the residual is small enough, which often happens well before n steps. It is commonly applied when A is large and sparse, so that factorising it would be costly.
The intuition behind the method
Rather than factorising A, CG builds a sequence of search directions that are conjugate (A-orthogonal) to one another, meaning pᵢᵀApⱼ = 0 for i ≠ j. Each new direction is built from the current residual and corrected by the previous direction, so progress made along earlier directions is not undone. Because each iteration needs only products of A with vectors, the matrix is never inverted and need not be stored in factored form. The iterates lie in the Krylov subspace spanned by r₀, Ar₀, …, A^{k−1}r₀, which is why CG is also called a Krylov subspace method; Saad (2003, chapters 6–7) treats this family of methods.
History
Hestenes and Stiefel's 1952 paper in the Journal of Research of the National Bureau of Standards presented an iterative procedure for a system of n equations in n unknowns that gives the solution in n steps, and showed it to be a special case of a more general method that includes Gaussian elimination. The paper also connected the method with orthogonal polynomials and continued fractions. Later treatments of CG as a practical method for large sparse problems are given by Saad (2003), whose chapters on Krylov subspace methods (6–7) and preconditioned iterations (9–10) cover the material.
When to use it
Choose CG when A is symmetric positive-definite, large and sparse, and products of A with vectors are available without storing A densely; a typical source is the discretisation of an elliptic partial differential equation. Check symmetry and definiteness of A before choosing it. If A is symmetric but indefinite, MINRES is the usual alternative, and if A is non-symmetric, GMRES or BiCG should be used instead. Do not use CG for small dense matrices, where direct factorisation such as LU or Cholesky is usually simpler and more efficient.
Limitations and considerations
- Requires A to be symmetric positive-definite; for symmetric indefinite systems the step-length denominator pᵀAp can vanish or change sign, and MINRES or GMRES are needed instead.
- In finite precision the computed residual can drift away from the true residual b − Ax and conjugacy is gradually lost, which can slow or stall convergence.
- Without preconditioning, ill-conditioned matrices converge slowly because the iteration count grows with the condition number.
- Applies only to linear systems; nonlinear problems need other approaches.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Needs only products of A with vectors and a few stored vectors, so the storage beyond A itself grows with n rather than with n².
- Terminates in at most n steps in exact arithmetic, so the iteration count is bounded in principle; if A has only m < n distinct eigenvalues, the exact solution is reached in at most m steps (Linear and Nonlinear Programming, 2016, §9.5). In practice the stopping point is set by the residual tolerance.
- The rate of convergence depends on the condition number of A, so a preconditioner that reduces the effective condition number can shorten the run considerably.
- Each iteration costs one product with A plus a few vector operations; the matrix–vector product parallelises readily, but the inner products in each iteration need global reductions, which can limit scaling on distributed-memory systems.
Applications
- Finite element analysis: solving the stiffness-matrix systems that arise in structural mechanics and acoustics.
- Image reconstruction: solving regularised least-squares systems in tomographic inverse problems such as CT and MRI.
- Regression: solving the normal equations of large least-squares problems, such as linear regression on large datasets.
- Geophysical inversion: solving the large linear systems that arise in seismic inversion.
- Fluid dynamics: solving pressure-correction (Poisson-type) equations in incompressible flow solvers.
How it works
How it works
Choose a starting guess x₀, compute the residual r₀ = b − Ax₀, and set the first search direction p₀ = r₀.
Compute the step length α_k = (r_kᵀr_k)/(p_kᵀAp_k), then update the iterate x_{k+1} = x_k + α_k p_k and the residual r_{k+1} = r_k − α_k A p_k. This is the exact step along p_k for a symmetric positive-definite A, not a generic line search, and it needs one product Ap_k per iteration.
Compute β_k = (r_{k+1}ᵀr_{k+1})/(r_kᵀr_k) and the next direction p_{k+1} = r_{k+1} + β_k p_k. In exact arithmetic, p_{k+1} is A-orthogonal to the earlier search directions.
Compare the residual norm ‖r_{k+1}‖ with the chosen tolerance. If it is below the tolerance, return x_{k+1}; otherwise return to the train step.
Common pitfalls
- Applying CG to a matrix that is not symmetric positive-definite without checking; the iteration can break down or fail to converge.
- Relying only on the residual produced by the recurrence; recompute b − Ax periodically to confirm that the stopping criterion is met.
- Omitting a preconditioner for an ill-conditioned problem; the effort of building one is often repaid by a large reduction in iterations.
- Treating the n-step bound as the expected cost; with rounding errors a run can need more iterations than the matrix size, and a restart may be required.
Frequently asked questions
What does conjugacy mean and why is it important?
Two vectors p_i and p_j are conjugate with respect to A if p_iᵀ A p_j = 0 for i ≠ j. Building each new search direction to be conjugate to the earlier ones means that progress made along earlier directions is not undone, which is what gives termination in at most n steps in exact arithmetic.
Why is preconditioning so critical for CG?
The standard convergence bound depends on √κ, where κ is the condition number of A. In the A-norm, the error after k iterations falls at least as fast as ((√κ−1)/(√κ+1))^k times its initial value, up to a constant factor, so a large κ forces many iterations. A preconditioner M, which must be symmetric positive-definite, replaces the system with an equivalent one whose effective condition number is smaller. In preconditioned CG each step solves M z_k = r_k, and z_k takes the place of r_k in the step-length and β formulas, with inner products taken with z. For ill-conditioned systems, the choice of preconditioner can matter as much as the choice of CG itself. Preconditioned iterations are treated in Saad (2003, chapters 9–10).
When should I use CG versus direct factorization (LU)?
For small dense systems, direct factorisation (LU or Cholesky) is usually simpler and more reliable. For large sparse systems, CG needs only products with A and avoids the fill-in that factorisation can create, so it is usually preferred. No single size threshold applies; the sparsity and structure of the matrix determine the choice.
How do I detect loss of orthogonality in finite precision?
Compute the true residual b − Ax periodically, not only the residual given by the recurrence. If the true residual is substantially larger than the recurrence residual, orthogonality has been lost; restart CG or use reorthogonalisation.
Related methods
Sources
Hestenes, M. R., & Stiefel, E. (1952). Methods of conjugate gradients for solving linear systems. Journal of Research of the National Bureau of Standards, 49(6), 409–436.
Open DOI referenceSaad, Y. (2003). Iterative Methods for Sparse Linear Systems (2nd ed.). SIAM.
Open DOI referenceNocedal, J., & Wright, S. J. (2006). Numerical Optimization (2nd ed.). Springer.
Open DOI reference2016_Book_LinearAndNonlinearProgramming, §9.5, p. 273