From first principles
Derive the first Krylov correction from an energy minimum
For symmetric positive definite \(A\), the unique solution of \(Ax=b\) minimizes a quadratic energy. For any trial state \(x\), moving along direction \(p\) by a scalar \(\alpha\) changes that energy according to
where \(r=b-Ax\) is the residual. Every nonzero direction has \(p^TAp>0\), so setting the derivative in \(\alpha\) to zero gives the unique line minimum. The residual at the updated state is then perpendicular to the search direction,
Starting with \(p=r\) searches the first Krylov space spanned by the initial residual. Expanding that space to include \(Ar,A^2r,\ldots\) permits a better energy minimum at each step. Conjugate gradients chooses directions mutually orthogonal under the \(A\)-weighted inner product so that later line searches preserve the minima already achieved in earlier directions.
Derivation and applications
Determine the decrease delivered by a preconditioned search direction
A preconditioner changes the scale and orientation of the direction used to correct a linear system. To see how that affects the objective, take symmetric positive definite \(A\) and preconditioner \(M\), with residual \(r=b-Ax\). Solve \(Mz=r\) to choose a direction. For nonzero \(r\), the product \(r^Tz=r^TM^{-1}r\) is positive, so a small positive step along \(z\) reduces the quadratic energy \(E=\tfrac12x^TAx-b^Tx\).
The minimum along this direction is at \(\alpha_*=(r^Tz)/(z^TAz)\). Substitution gives the exact energy decrease. If \(x_*\) solves the original system, the full energy difference to the solution is also a quadratic form,
Their ratio is a squared cosine. Let \(u=A^{-1/2}r\) and \(v=A^{1/2}z\); their ordinary dot product is \(r^Tz\). The first search removes the fraction
A direction proportional to the exact correction removes all the error. A positive scalar multiple of \(M\) changes the step length inversely to the direction length, preserving the updated point. These facts concern one search and also apply to the first step of preconditioned conjugate gradients.
Worked example
Compare two directions on the same system
Take \(A=\operatorname{diag}(1,9)\), \(r=(1,3)^T\) and initial state zero. The available energy decrease is
Without preconditioning \(z=r\), so the first step removes \(10^2/[2(1+81)]=0.610\). With \(M=\operatorname{diag}(1,3)\), \(z=(1,1)^T\); it removes \(4^2/[2(1+9)]=0.800\). Both updates solve the same physical balances.
Second application
Rescale an exact preconditioner
In a second problem \(A=\operatorname{diag}(2,5)\), \(r=(4,10)^T\) and the available solver uses \(M=2A\). Its direction is \((1,1)^T\). The minimizing step is \((4+10)/(2+5)=2\), giving correction \((2,2)^T=A^{-1}r\). Judging a preconditioner by whether the step length is close to unity would reject this exact one-step correction.
OneSimulation laboratory
Separate algebraic error from mesh error
Start from this chapter. Relax the CG residual tolerance on a fixed grid. Observe the departure from the direct solution, then compare with the shift caused by spatial refinement at tight tolerance.
Compare recorded OneSimulation runs on this page. To test your own inputs, download the Python model and run the model in an activated OneSimulation environment.
A unit cube has conductivity 1 W/(m·K), uniform heating 1 W/m³ and zero temperature rise on every face. The script compares CG and a direct solver on the same trilinear finite-element mesh. Predict the effects of first refining the mesh and then relaxing only the CG tolerance. Download the Python experiment · OneSimulation linear solvers.
python linear-algebra.py
python linear-algebra.py --cells 10
python linear-algebra.py --cells 10 --rtol 0.05
| Cells per axis, CG tolerance | Direct peak (K) | CG peak (K) | Max. difference (K) |
|---|---|---|---|
| 5, 10⁻¹⁰ | 0.05483074 | 0.05483074 | 2.8 × 10⁻¹⁷ |
| 10, 10⁻¹⁰ | 0.05708900 | 0.05708900 | 3.6 × 10⁻¹³ |
| 10, 0.05 | 0.05708900 | 0.05620782 | 8.8 × 10⁻⁴ |

The refined mesh includes the cube centre as a node, whereas the five-cell mesh samples the peak off-centre. The change between direct nodal maxima therefore includes a sampling effect. The final two rows use identical nodes, isolating the effect of the CG stopping test. Differences near roundoff can vary between implementations.
Change parameters · Change the laboratory inputs
Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.
Problem sheet 3 · Bound the effect of stopping a linear solve early
A geometrical interpretation of positive definiteness
Assume \(A=A^T\) and \(v^TAv>0\) for all nonzero \(v\). The algebraic solution \(x_\star\) is the unique minimiser of \(J(x)=x^TAx/2-b^Tx\). Indeed, completing the square gives
For a structural stiffness matrix this has the interpretation of excess elastic potential energy. The negative gradient at an approximation is the residual \(r=b-Ax\). Even in a purely algebraic application this energy geometry explains which approximation CG selects.
In a chosen search direction \(p\), minimise \(J(x+\alpha p)\) by differentiation. The optimal step is
Two successive minimisations should not undo each other. If \(p_i^TAp_j=0\) for distinct directions, minimisation along \(p_j\) preserves minimisation along \(p_i\). Such directions are called conjugate. CG generates them from successive residuals and matrix-vector products. Starting with \(p_0=r_0\), the exact-arithmetic recurrences are \(\alpha_k=(r_k^Tr_k)/(p_k^TAp_k)\), \(r_{k+1}=r_k-\alpha_kAp_k\),
Work through a two-dimensional example
Take \(A=\operatorname{diag}(1,4)\), \(b=(1,1)^T\), and \(x_0=0\). Then \(p_0=(1,1)^T\), \(Ap_0=(1,4)^T\) and \(\alpha_0=2/5=0.4\). The first approximation is \((0.4,0.4)^T\); its residual is \((0.6,-0.6)^T\). That residual is perpendicular to the old search direction because the line minimum has already been reached. The update coefficient is \(\beta_0=0.72/2=0.36\), giving \(p_1=(0.96,-0.24)^T\).
Check the conjugacy directly:
Now \(p_1^TAp_1=1.152\), so
The second approximation is \((1,0.25)^T\), which solves the system. A repeated steepest descent restart would search along the new residual, lose conjugacy, and generally need more than two steps. In floating-point arithmetic, residual orthogonality gradually deteriorates. A fresh residual computed from the final vector is a valuable check.
Improve the geometry of the search
At iteration \(k\), candidates lie in \(x_0+\operatorname{span}\{r_0,Ar_0,\ldots,A^{k-1}r_0\}\). The error can be written \(p_k(A)e_0\) for a polynomial with \(p_k(0)=1\). If the operator has only a few distinct eigenvalues, a low-degree polynomial can vanish on them all. More generally, many eigenvalues in a tight cluster can be reduced together. This explains why the condition number gives only a worst-case convergence estimate.
A positive definite preconditioner \(M\) corresponds to solving with \(M^{-1/2}AM^{-1/2}\). For the diagonal example, \(M=\operatorname{diag}(A)\) makes the transformed operator the identity, so one step suffices. For a full matrix, the same choice corrects scales but may leave strong coupling untouched. Applying an approximate inverse also costs time and memory. Compare total solve time, setup cost and physical error over representative loads before choosing a preconditioner. The heated cube experiment reports how changing the tolerance alters the same temperature observable on a fixed mesh. Compare direct and iterative heat balances.
Read an energy-norm convergence estimate
For symmetric positive definite \(A\), a classical CG estimate is \(\|e_k\|_A/\|e_0\|_A\leq2[(\sqrt\kappa-1)/(\sqrt\kappa+1)]^k\). To see the square root appear, minimise the largest magnitude of an error polynomial over the entire eigenvalue interval \([\lambda_{\min},\lambda_{\max}]\), with its value fixed at one at zero. Shifting a Chebyshev polynomial onto that interval produces the stated decay. Treating every point of the interval as a possible eigenvalue makes this a deliberately pessimistic estimate when the actual eigenvalues form tight clusters.
For \(\kappa=100\), the factor is \(9/11\). The bound first guarantees a reduction below \(10^{-3}\) after 38 iterations. If effective preconditioning reduces the condition number to 4, the factor becomes \(1/3\) and seven iterations suffice for the same guarantee. The comparison gives a budget for the search iterations only. An expensive preconditioner can erase that saving when it is set up for a single small load case. For repeated loads, setup can be spread over many solves, changing the economics without changing the convergence analysis.
Relate the stopping norm to energy
For a symmetric positive definite system the energy error squared equals \(r^TA^{-1}r\), since \(r=Ae\). Consequently residuals with the same Euclidean length may have different physical significance. With \(A=\operatorname{diag}(1,100)\), residuals \((1,0)^T\) and \((0,1)^T\) both have length one, but their energy errors are 1 and 0.1. A tolerance derived from an energy specification should account for this spectral weighting.
Turn a known spectral interval into a polynomial guarantee
Let \(A\) be symmetric positive definite with spectrum in \([a,b]\), \(0<a<b\). After \(k\) conjugate-gradient steps from \(x_0\), every available state error has the form \(p(A)e_0\), where \(p\) has degree at most \(k\) and \(p(0)=1\). The constraint at zero follows because the correction is an element of the Krylov space generated by the initial residual \(Ae_0\). Expressing \(e_0\) in orthonormal eigenvectors shows that the squared energy error is \(\sum_i\lambda_i |p(\lambda_i)|^2 |e_{0,i}|^2\). Bounding the maximum of the polynomial over the entire spectral interval gives a guarantee independent of the initial error.
Map \([a,b]\) to \([-1,1]\) through \(s=(a+b-2\lambda)/(b-a)\). The degree-\(k\) Chebyshev polynomial \(T_k(s)\) has magnitude at most one there, while at \(\lambda=0\) its argument \(s_0=(a+b)/(b-a)\) exceeds one. Thus \(p(\lambda)=T_k(s)/T_k(s_0)\) is an admissible trial polynomial with worst amplitude \(1/T_k(s_0)\). Since CG minimises the energy norm over all trial corrections, it performs at least as well as this explicit choice. Positive definiteness is used twice: it defines the energy norm and keeps zero outside the proposed spectral interval.
Compare an interval bound with the actual finite spectrum
Suppose the only eigenvalues are 1, 2 and 4. For two steps take \(T_2(s)=2s^2-1\), \(s_0=5/3\). Then \(T_2(s_0)=41/9\), so the worst relative energy error is at most \(9/41\approx0.2195\) for the trial polynomial and hence for CG. At the spectral endpoints the polynomial equals \(9/41\). At \(\lambda=2\), however, \(s=1/3\) and the factor is \(-7/41\). Each mode has acquired a small amplitude even though the signs differ. The actual energy error depends on how much of the initial energy lay in each mode.
For three steps the spectral interval still has infinitely many possible points. But the actual three eigenvalues permit the polynomial \((1-\lambda)(1-\lambda/2)(1-\lambda/4)\), which equals one at zero and vanishes on the entire spectrum. CG can therefore reach the exact solution on this finite example in at most three steps in exact arithmetic. Repeated eigenvalues do not increase this bound. The interval guarantee loses this information by preparing for every point between the smallest and largest eigenvalues, including values absent from the matrix.
A strong preconditioner can produce a narrow spectral cluster plus a few outliers. A helpful interpretation is to spend a small number of polynomial roots suppressing the outliers and use the rest to approximate zero across the cluster. The number of distinct eigendirections and the distribution of initial energy then complement a simple condition-number estimate. Finite precision can spoil exact finite termination, particularly when supposedly eliminated components reappear through roundoff.
If \(A\) is instead indefinite, a polynomial residual argument may still be meaningful for a different Krylov solver, but the quantity \(e^TAe\) can vanish for nonzero error or become negative. The preceding minimisation proof then loses the positive measure of approximation on which it depends. Checking symmetry alone is insufficient to apply it.
Same condition number, different Krylov histories
Solve two positive diagonal systems from zero with identical right-hand sides. Both have extreme eigenvalues 1 and 100. Plot the error in \(\|e\|_A=\sqrt{e^\mathsf{T}Ae}\), using the known diagonal inverse as a reference.

Read values from the plot
| Conjugate-gradient iterations | Two distinct eigenvalues | Twenty logarithmically spaced |
|---|---|---|
| 0 | 1 | 1 |
| 4 | 1e−15 | 0.54871 |
| 8 | 1e−15 | 0.22333 |
| 12 | 1e−15 | 0.057405 |
| 16 | 1e−15 | 0.0058119 |
Change parameters · Same condition number, different Krylov histories
Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.