M2 · Conjugate gradient and structured quadratics, from zero

Lectures 11–13 (17–24 Sep) · MT2 material · about 2.5 hours with practice · Goal: run CG by hand on a small quadratic, and answer "in how many iterations does CG converge?" for matrices like $\alpha I+uu^\top+2vv^\top$, with reasons.

How this page works

Same as M1: a story, each section using only what came before; Check boxes as you go; the Summary card at the end is for revision. This page builds on M1 (exact line search, eigenvalues of a quadratic, zig-zag).

Why this module is second: CG appeared in 2016 (Q2, Q3, Q4), 2020 (P1 Q4), 2025 (Q3, which was 2016 Q4 again), as T/F items in 2024 and 2025, and as 4 of the 6 MT2 questions this year.

Notation (his, from MT2):

  • $d$ = dimension ($x\in\mathbb R^d$). $S^d$ = symmetric $d\times d$ matrices.
  • $f(x)=\frac12x^\top Qx-h^\top x+c$ with $Q\in S^d$, $Q\succ0$ (symmetric, positive definite). Minimiser $x^*=Q^{-1}h$. $\kappa=\lambda_{\max}/\lambda_{\min}$ (condition number, as in M1).
  • $g^{(k)}=\nabla f(x^{(k)})=Qx^{(k)}-h$ = gradient at step $k$. (In a linear system it is minus the "residual" $h-Qx$.)
  • $u^{(k)}$ = search direction; $\alpha_k$ = step length; $\beta_k$ = the mixing number in CG.
  • $E(x)=\frac12(x-x^*)^\top Q(x-x^*)=f(x)-f^*$: the error measure he uses (same as $\Delta$ in M1).
  • $(\lambda_i,v_i)$ = eigenvalue and unit eigenvector of $Q$: $Qv_i=\lambda_iv_i$. Because $Q$ is symmetric, the $v_i$ can be chosen orthonormal.
  • The start error $x^{(0)}-x^*=\sum_ic_iv_i$ touches eigenvalue $\lambda_i$ if $c_i\ne0$ (it has a component along that eigenvector).
  • In section E, I write structured matrices as $\sigma I+aa^\top+2bb^\top$ so letters don't clash; his papers write $\alpha I+uu^\top+2vv^\top$ (there $\alpha$ is a number in the matrix, not a step length).

0. Why CG exists

In M1, steepest descent on a quadratic zig-zags: each exact line search fixes the current direction, but the next step partly undoes the progress made along earlier directions. With condition number $\kappa$ it needs a number of steps proportional to $\kappa$ for each extra digit of accuracy.

The fix: choose directions so that minimising along a new direction never spoils what was achieved along the old ones. Then each line search finishes one "coordinate" for good, and a $d$-dimensional quadratic is solved in at most $d$ steps. Such directions are called $Q$-conjugate. Conjugate gradient (CG) is the clever way of producing them cheaply, one at a time, from gradients.

The whole module in one sentence

CG minimises a quadratic in at most as many steps as the number of different eigenvalues that the starting error actually touches, and the exam is mostly about counting those.

Roadmap: A defines conjugacy. B shows why conjugate directions finish in $d$ steps. C builds CG and runs it by hand. D counts the steps (polynomial view). E applies the count to structured matrices. F uses CG for linear systems. G is the exam recipe.

A. Conjugate directions

In plain words: two directions are $Q$-conjugate if they are perpendicular after you measure angles the way $Q$ does. If you stretch space so the elliptical level sets of $f$ become circles, conjugate directions become ordinary perpendicular directions.

Definition

Nonzero vectors $u_1,\dots,u_m$ are $Q$-conjugate if $\;u_i^\top Qu_j=0\;$ for all $i\neq j$.

With $Q=I$ this is just "orthogonal".

With numbers

$Q=\mathrm{diag}(1,4)$, $u=(1,1)$. Find $v$ conjugate to $u$: $u^\top Qv=v_1+4v_2=0$, e.g. $v=(4,-1)$. They are conjugate, but not orthogonal ($u^\top v=3$).

Three facts that are T/F favourites:

  1. Conjugate ⇒ linearly independent, if $Q\succ0$. Suppose $\sum_jc_ju_j=0$. Multiply by $u_i^\top Q$: all cross terms vanish, leaving $c_i\,u_i^\top Qu_i=0$. Since $Q\succ0$ and $u_i\ne0$, $u_i^\top Qu_i>0$, so $c_i=0$. Hence a matrix whose columns are conjugate directions has full column rank (MT2 T/F (b): True), and there are at most $d$ of them.
  2. If $Q$ is not positive definite this can fail (2016 Q2). Example: $Q=\mathrm{diag}(1,0)$, $a_1=e_2$, $a_2=2e_2$: $a_1^\top Qa_2=0$, yet $a_2=2a_1$. The proof breaks because $a_i^\top Qa_i$ can be $0$.
  3. Conjugate directions are not unique (MT2 T/F (a): False). Any eigenvector basis of $Q$ works, and so does conjugating any independent set (next point).

Making conjugate directions from any independent vectors (MT2 Q3(b)). This is Gram–Schmidt with the $Q$-inner product: $u_1=v_1$ and

$$u_i=v_i-\sum_{j<i}A_{ij}u_j,\qquad A_{ij}=\frac{v_i^\top Qu_j}{u_j^\top Qu_j}.$$

Why: take $u_l^\top Q$ of both sides for some $l<i$; the earlier $u_j$ are already conjugate, so only $j=l$ survives: $u_l^\top Qu_i=v_i^\top Qu_l-A_{il}u_l^\top Qu_l$, which is $0$ for that $A_{il}$.

Check A. $Q=\begin{pmatrix}2&1\\1&2\end{pmatrix}$, $v_1=(1,0)$, $v_2=(0,1)$. Conjugate them.
Show answer

$u_1=(1,0)$. $A_{21}=\frac{v_2^\top Qu_1}{u_1^\top Qu_1}=\frac12$. $u_2=(0,1)-\frac12(1,0)=(-\frac12,1)$. Check: $u_1^\top Qu_2=(2,1)\cdot(-\frac12,1)=0$ ✓.

B. Why conjugate directions finish in $d$ steps

Idea: write the unknown point in "conjugate coordinates". Then $f$ splits into separate one-variable parabolas, one per direction, and each can be minimised on its own.

  1. Take any start point $a$ (later: $a=x^{(0)}$) and conjugate directions $u_1,\dots,u_m$ (columns of a matrix $U$). Points of the form $x=a+Uy=a+\sum_iy_iu_i$.
  2. Expand: $f(a+Uy)=f(a)+\nabla f(a)^\top Uy+\frac12y^\top U^\top QUy$. Conjugacy makes $U^\top QU$ diagonal (off-diagonal entries are $u_i^\top Qu_j=0$). So $$f(a+Uy)=f(a)+\sum_i\Big(y_i\,\nabla f(a)^\top u_i+\tfrac12y_i^2\,u_i^\top Qu_i\Big):$$ a sum of separate parabolas, one in each $y_i$.
  3. Minimise each: $\boxed{\,y_i=-\dfrac{\nabla f(a)^\top u_i}{u_i^\top Qu_i}\,}$ (MT2 Q2, worth 5 marks). The general optimality condition is $U^\top\nabla f(a+Uy)=U^\top(\nabla f(a)+QUy)=0$; conjugacy is what makes it solvable coordinate by coordinate.
  4. So line-searching along $u_1$, then $u_2$, … (the conjugate direction method) sets $y_1,y_2,\dots$ one at a time, and a later step never changes an earlier $y_i$. (Why the line search at $x^{(k)}$ finds the same $y_k$ as the formula, which uses $\nabla f(a)$: $g^{(k)}=\nabla f(a)+Q(x^{(k)}-a)$, and $x^{(k)}-a$ is a combination of earlier $u_j$, all conjugate to $u_k$, so $g^{(k)\top}u_k=\nabla f(a)^\top u_k$.) After $d$ steps (with $d$ independent directions), $x$ is the minimiser over all of $\mathbb R^d$: $x^{(d)}=x^*$.
Expanding Subspace Theorem (his name)

For the conjugate direction method $x^{(k+1)}=x^{(k)}+\alpha_ku^{(k)}$ with exact steps $\alpha_k=-\frac{g^{(k)\top}u^{(k)}}{u^{(k)\top}Qu^{(k)}}$:

  • $g^{(k)\top}u^{(i)}=0$ for all $i<k$: the new gradient is perpendicular to every direction used so far;
  • $x^{(k)}$ minimises $f$ over the whole set $x^{(0)}+\mathrm{span}\{u^{(0)},\dots,u^{(k-1)}\}$ (the "expanding subspace").

It holds for any set of conjugate directions, not just CG's (MT2 T/F (c), "does not apply to arbitrary conjugate directions": False).

Two conjugate steps finish a 2-D quadratic

Ellipses are level sets of a 2-D quadratic. Pick the first direction with the angle slider; the second is computed to be $Q$-conjugate to it. Each step is an exact line search. Click inside the picture to move the start. Faint grey: steepest descent from the same start.

What to notice: whatever first direction you choose, the second (conjugate) step lands exactly on the centre. The two directions usually do not look perpendicular; they are perpendicular "as $Q$ sees it". Steepest descent (grey) is still zig-zagging.

C. The conjugate gradient algorithm

C1. The idea: build each direction from the newest gradient

We need conjugate directions, but computing eigenvectors or doing a full Gram–Schmidt is expensive. CG gets them almost for free: start with steepest descent, then each new direction is the new negative gradient plus a little of the previous direction, with the "little" ($\beta_k$) chosen to make it conjugate to the previous one. A small miracle (the CG theorem) makes it conjugate to all earlier ones too.

CG algorithm (state it exactly: 2016 Q3 was "State the CG algorithm", 5 marks)
  1. Start: $x^{(0)}$ given, $g^{(0)}=Qx^{(0)}-h$, $u^{(0)}=-g^{(0)}$.
  2. While $g^{(k)}\ne0$: $$\alpha_k=\frac{g^{(k)\top}g^{(k)}}{u^{(k)\top}Qu^{(k)}},\qquad x^{(k+1)}=x^{(k)}+\alpha_ku^{(k)},\qquad g^{(k+1)}=g^{(k)}+\alpha_kQu^{(k)},$$ $$\beta_k=\frac{g^{(k+1)\top}g^{(k+1)}}{g^{(k)\top}g^{(k)}},\qquad u^{(k+1)}=-g^{(k+1)}+\beta_ku^{(k)}.$$

Rationale (MT2 Q3(a)): $\alpha_k$ minimises $f$ along $u^{(k)}$ (exact line search); $\beta_k$ makes $u^{(k+1)}$ $Q$-conjugate to $u^{(k)}$.

Where the two formulas come from (if asked to justify)

Exact line search gives $\alpha_k=-\frac{g^{(k)\top}u^{(k)}}{u^{(k)\top}Qu^{(k)}}$ (section B). Since $u^{(k)}=-g^{(k)}+\beta_{k-1}u^{(k-1)}$ and $g^{(k)\top}u^{(k-1)}=0$ (Expanding Subspace), $-g^{(k)\top}u^{(k)}=g^{(k)\top}g^{(k)}$.

Conjugacy $u^{(k+1)\top}Qu^{(k)}=0$ gives $\beta_k=\frac{g^{(k+1)\top}Qu^{(k)}}{u^{(k)\top}Qu^{(k)}}$; using $Qu^{(k)}=(g^{(k+1)}-g^{(k)})/\alpha_k$ and orthogonality of gradients this simplifies to $\frac{\|g^{(k+1)}\|^2}{\|g^{(k)}\|^2}$.

C2. What CG guarantees (the CG theorem)

  • Directions are mutually $Q$-conjugate: $u^{(i)\top}Qu^{(j)}=0$, $i\ne j$.
  • Gradients are mutually orthogonal: $g^{(i)\top}g^{(j)}=0$, $i\ne j$. (Orthogonal, not conjugate: a T/F trap.)
  • $\mathrm{span}\{g^{(0)},\dots,g^{(k)}\}=\mathrm{span}\{u^{(0)},\dots,u^{(k)}\}=\mathrm{span}\{g^{(0)},Qg^{(0)},\dots,Q^kg^{(0)}\}$. The last set (the start gradient multiplied by powers of $Q$) is called the Krylov space.
  • Each $u^{(k)}$ is a descent direction while $g^{(k)}\ne0$: $g^{(k)\top}u^{(k)}=-\|g^{(k)}\|^2+\beta_{k-1}g^{(k)\top}u^{(k-1)}=-\|g^{(k)}\|^2<0$. (Careful: his MT2 key marks the T/F "CG directions are always descent directions" as False. See Practice P4.)
  • Finite termination: $x^{(k)}=x^*$ for some $k\le d$ (exact arithmetic).
  • Restarting (setting $\beta=0$) every iteration turns CG into steepest descent, so it is slower, not faster (MT2 T/F (e): False).

C3. One full run by hand

Worked: $Q=\begin{pmatrix}3&1\\1&3\end{pmatrix}$, $h=(2,0)$, $x^{(0)}=0$
  1. $g^{(0)}=Qx^{(0)}-h=(-2,0)$, so $u^{(0)}=(2,0)$.
  2. $Qu^{(0)}=(6,2)$, $u^{(0)\top}Qu^{(0)}=12$, $g^{(0)\top}g^{(0)}=4$: $\alpha_0=\frac4{12}=\frac13$. $x^{(1)}=(\frac23,0)$.
  3. $g^{(1)}=g^{(0)}+\alpha_0Qu^{(0)}=(-2,0)+\frac13(6,2)=(0,\frac23)$. Check: $g^{(1)\top}g^{(0)}=0$ ✓.
  4. $\beta_0=\frac{4/9}{4}=\frac19$. $u^{(1)}=-g^{(1)}+\frac19u^{(0)}=(\frac29,-\frac23)$. Check conjugacy: $u^{(0)\top}Qu^{(1)}=(2,0)\cdot Qu^{(1)}$ with $Qu^{(1)}=(0,-\frac{16}9)$: $=0$ ✓.
  5. $u^{(1)\top}Qu^{(1)}=(-\frac23)(-\frac{16}9)=\frac{32}{27}$, $g^{(1)\top}g^{(1)}=\frac49$: $\alpha_1=\frac{4/9}{32/27}=\frac38$.
  6. $x^{(2)}=(\frac23,0)+\frac38(\frac29,-\frac23)=(\frac34,-\frac14)$. And $Q^{-1}h=\frac18\begin{pmatrix}3&-1\\-1&3\end{pmatrix}(2,0)=(\frac34,-\frac14)$ ✓. Done in 2 steps ($d=2$). Steepest descent from the same start is still about $0.009$ above $f^*$ after 2 steps.
Check C. In the run above, what is $g^{(1)\top}u^{(1)}$, and why must it be $-\|g^{(1)}\|^2$?
Show answer

$(0,\frac23)\cdot(\frac29,-\frac23)=-\frac49=-\|g^{(1)}\|^2$. Because $u^{(1)}=-g^{(1)}+\beta_0u^{(0)}$ and $g^{(1)}\perp u^{(0)}$: the new direction is a descent direction.

D. How many steps? The polynomial view

"At most $d$" is a weak answer. The exam wants the exact count for a given $Q$ and start. The tool is the polynomial view from class.

D1. CG picks the best polynomial

  1. Every iterate lies in $x^{(0)}+\mathrm{span}\{g^{(0)},Qg^{(0)},\dots,Q^{k-1}g^{(0)}\}$ (C2), so $x^{(k)}=x^{(0)}+P_{k-1}(Q)g^{(0)}$ for some polynomial $P_{k-1}$ of degree $k-1$.
  2. Since $g^{(0)}=Q(x^{(0)}-x^*)$: $\;x^{(k)}-x^*=\big(I+QP_{k-1}(Q)\big)(x^{(0)}-x^*)$. Call $R_k(\lambda)=1+\lambda P_{k-1}(\lambda)$: a degree-$k$ polynomial with $R_k(0)=1$.
  3. Write the start error in eigenvectors: $x^{(0)}-x^*=\sum_ic_iv_i$. A polynomial of $Q$ acts on $v_i$ as the number $R_k(\lambda_i)$ (because $Qv_i=\lambda_iv_i$ gives $Q^2v_i=\lambda_i^2v_i$, and so on). Using that the $v_i$ are orthonormal, $$E(x^{(k)})=\tfrac12\sum_i\lambda_i\,R_k(\lambda_i)^2\,c_i^2 .$$
  4. By the Expanding Subspace Theorem, CG's $x^{(k)}$ is the best point in that set, i.e. CG uses the best such polynomial. So for any $R_k$ with $R_k(0)=1$:
The CG bound (MT2 Q4(a), stated as in his solution) $$E(x^{(k)})\le\max_{1\le i\le d}\big(1+\lambda_iP_{k-1}(\lambda_i)\big)^2\;E(x^{(0)})\qquad\text{for every polynomial }P_{k-1}\text{ of degree }k-1.$$

Only eigenvalues whose $c_i\ne0$ (touched by the start error) matter in the max.

D2. Three consequences, each an exam question

  1. $r$ distinct eigenvalues ⇒ at most $r$ steps (MT2 Q4(c)). Choose $R_r(\lambda)=\prod_{j=1}^r(1-\lambda/\tau_j)$ over the distinct values $\tau_j$: it is $0$ at every eigenvalue and $R_r(0)=1$. So $E(x^{(r)})=0$.
  2. Start error touches only some eigenvectors ⇒ only those count (MT2 Q5). If $x^{(0)}-x^*$ (equivalently $g^{(0)}$) lies in the span of $v_5,v_9$, the Krylov space never leaves $\mathrm{span}\{v_5,v_9\}$, and $R_2(\lambda)=(1-\frac\lambda{\lambda_5})(1-\frac\lambda{\lambda_9})$ kills both: 2 steps.
  3. One step ($k=1$) = steepest descent with exact line search ($u^{(0)}=-g^{(0)}$). Then $P_0=c$ is a constant and the bound is $\min_c\max_i(1+c\lambda_i)^2$. The best $c=-\frac{2}{\lambda_{\min}+\lambda_{\max}}$ gives $\big(\frac{\lambda_{\max}-\lambda_{\min}}{\lambda_{\max}+\lambda_{\min}}\big)^2$, the M1 exact-line-search rate. (This $c$ is a tool for the bound; CG's actual step is at least as good as any $c$, so the bound holds.)
Worked: MT2 Q4(b) (5 marks)

Eigenvalues between 30 and 90. True or false: $E(x^{(1)})\le0.3\,E(x^{(0)})$? Better bound?

  1. $k=1$: $P_0(\lambda)=c$. Take $c=-\frac{2}{30+90}=-\frac1{60}$.
  2. Then $1+c\lambda$ runs from $1-\frac{30}{60}=0.5$ to $1-\frac{90}{60}=-0.5$: $|1+c\lambda_i|\le0.5$ for every eigenvalue in $[30,90]$.
  3. So $E(x^{(1)})\le0.5^2E(x^{(0)})=0.25E(x^{(0)})\le0.3E(x^{(0)})$: True, and $0.25$ is the better bound.
The one-step polynomial $|1+c\lambda|$

The bound after one step is $\max_i|1+c\lambda_i|^2$. Slide $c$ and watch the worst eigenvalue (the max sits at an end of the interval). Defaults are MT2 Q4(b).

What to notice: the best $c$ makes the two ends equal in size, $1+c\lambda_{\min}=-(1+c\lambda_{\max})$, giving $c=-2/(\lambda_{\min}+\lambda_{\max})$.

D3. The general rate (for T/F)

For $k$ steps, a Chebyshev polynomial gives $\;\|x^{(k)}-x^*\|_Q\le2\Big(\frac{\sqrt\kappa-1}{\sqrt\kappa+1}\Big)^k\|x^{(0)}-x^*\|_Q$: CG's speed depends on $\sqrt\kappa$, gradient descent's on $\kappa$. For $\kappa=100$, per step in the $Q$-norm $\|z\|_Q=\sqrt{z^\top Qz}$: GD factor $\frac{99}{101}\approx0.98$, CG $\frac{9}{11}\approx0.82$. And after the same number of steps CG is never worse than gradient descent with any step sizes.

CG step counter: which eigenvalues does the start touch?

$Q$ is diagonal with the 10 eigenvalues listed. Tick which eigen-directions the starting error contains. The plot shows $\log_{10}\big[E(x^{(k)})/E(x^{(0)})\big]$: blue = CG, grey = steepest descent (exact line search). "Reaches" means $E/E_0<10^{-12}$. Ticks stay when you switch presets.

What to notice: the CG count equals the number of different eigenvalues among the ticked ones. With clusters (last preset) CG drops fast in the first steps (one per cluster), then needs a few more steps to clean up the spread inside each cluster.

E. Structured matrices: $\sigma I+aa^\top+2bb^\top$ and friends

He likes matrices built from a multiple of $I$ plus a few rank-one pieces. Their eigenvalues can be found without any determinant: just apply $Q$ to the obvious vectors.

E1. Eigenvalues by applying $Q$

Let $Q=\sigma I+aa^\top+2bb^\top$ with $\|a\|=\|b\|=1$ and $a^\top b=0$.

  • $Qa=\sigma a+a(a^\top a)+2b(b^\top a)=(\sigma+1)a$: eigenvalue $\sigma+1$.
  • $Qb=\sigma b+a(a^\top b)+2b(b^\top b)=(\sigma+2)b$: eigenvalue $\sigma+2$.
  • Any $w\perp a,b$: $Qw=\sigma w$. That is a $(d-2)$-dimensional space: eigenvalue $\sigma$, repeated $d-2$ times.

So there are at most 3 distinct eigenvalues ($\sigma$, $\sigma+1$, $\sigma+2$; exactly 3 when $d\ge3$), however large $d$ is. CG from any start: at most 3 steps.

E2. Which ones does the start touch?

For $f=\frac12x^\top Qx+w^\top x+c$ (his 2025 sign) started at $x^{(0)}=0$: $g^{(0)}=w$. The count is the number of distinct eigenvalues present in $w$.

Worked: 2025 final Q3 (10 marks), which was 2016 Q4

$Q=\alpha I+uu^\top+2vv^\top$, $\alpha>0$, $\|u\|=\|v\|=1$, $u^\top v=0$, $f(x)=\frac12x^\top Qx+w^\top x+c$ with $w^\top u=w^\top v=0$.

  1. (a) Eigenvalues: $\alpha$ ($d-2$ times), $\alpha+1$, $\alpha+2$ (E1).
  2. (b) Optimum: $Q\succ0$ (all eigenvalues $>0$), so the minimiser solves $Qx+w=0$. Since $w$ lies in the $\alpha$-eigenspace, $Qw=\alpha w$ and $x^*=-\frac1\alpha w$. Value: $f^*=\frac12\cdot\frac{\|w\|^2}{\alpha}-\frac{\|w\|^2}{\alpha}+c=c-\frac{\|w\|^2}{2\alpha}$.
  3. (b) $\alpha=0$: then $Qw=0$, so $f(tw)=t\|w\|^2+c\to-\infty$ as $t\to-\infty$ (if $w\ne0$): no minimum. (If $w=0$, every $x$ with $Qx=0$ is a minimiser.)
  4. (c) CG from $x^{(0)}=0$: $g^{(0)}=w$, an eigenvector (eigenvalue $\alpha$). One distinct eigenvalue touched ⇒ 1 iteration. Explicitly $u^{(0)}=-w$, $\alpha_0=\frac{w^\top w}{w^\top Qw}=\frac1\alpha$, $x^{(1)}=-\frac1\alpha w=x^*$, and $g^{(1)}=0$.
Worked: 2016 final Q4 (the singular version, 10 marks)

Same but $Q=uu^\top+2vv^\top$ (no $\alpha I$), so for $d\ge3$, $Q$ is only positive semidefinite.

  1. (a) $w\perp u,v$, $x^{(0)}=0$: $g^{(0)}=w$ and $Qw=0$. The first step needs $u^{(0)\top}Qu^{(0)}=w^\top Qw=0$ in the denominator: CG breaks down at the first step. The reason: along $-w$, $f(-tw)=-t\|w\|^2+c\to-\infty$. There is no minimiser at all.
  2. (b) $w=pu+qv$ with numbers $p^2+q^2=1$ (the paper calls them $\alpha,\beta$): now $g^{(0)}=w$ lives in $\mathrm{span}\{u,v\}$ with eigenvalues 1 and 2. Both touched ($p,q\ne0$) ⇒ 2 iterations, reaching $x=-(pu+\frac q2v)$ (solve $Qx=-w$ inside $\mathrm{span}\{u,v\}$). If $p=0$ or $q=0$: 1 iteration.

E3. Rank-one pieces in general

  • $Q=\sigma I+(\text{symmetric rank-}r\text{ matrix})$ ⇒ eigenvalue $\sigma$ on a $(d-r)$-dimensional space, so at most $r+1$ distinct eigenvalues ⇒ CG in at most $r+1$ steps. E.g. $I+aa^\top+bb^\top$ (any $a,b$): at most 3.
  • $\frac12(x^\top v_1)^2=\frac12x^\top(v_1v_1^\top)x$ has Hessian $v_1v_1^\top$: rank one, PSD, so convex but not strictly (2021 Q2). Adding $\frac12\|x\|^2$ makes the Hessian $I+v_1v_1^\top\succ0$.
Check E. $Q=3I+2aa^\top$ in $\mathbb R^4$, $\|a\|=1$. Eigenvalues? CG steps from a general start? From $x^{(0)}=0$ with $h=4a$ (using $f=\frac12x^\top Qx-h^\top x$)? What is $x^*$ then?
Show answer

$Qa=5a$, and $Qw=3w$ for $w\perp a$: eigenvalues $3,3,3,5$. General start: 2 steps. With $h=4a$: $g^{(0)}=-4a$ touches only eigenvalue 5: 1 step, $x^*=Q^{-1}h=\frac45a$.

F. CG for a linear system $Ax=b$ (2020 P1 Q4)

  • Why it works: if $A$ is symmetric positive definite, solving $Ax=b$ is the same as minimising $\phi(x)=\frac12x^\top Ax-b^\top x$, since $\nabla\phi=Ax-b$. The residual $\mathrm{res}(x)=b-Ax$ is minus the gradient. CG on $\phi$ written with residuals $r^{(k)}=b-Ax^{(k)}$ is the algorithm printed in 2020 Q4: $u^{(0)}=r^{(0)}$; $\alpha_k=\frac{\|r^{(k)}\|^2}{u^{(k)\top}Au^{(k)}}$; $x^{(k+1)}=x^{(k)}+\alpha_ku^{(k)}$; $r^{(k+1)}=r^{(k)}-\alpha_kAu^{(k)}$; $\beta_k=\frac{\|r^{(k+1)}\|^2}{\|r^{(k)}\|^2}$; $u^{(k+1)}=r^{(k+1)}+\beta_ku^{(k)}$.
  • When it doesn't apply: CG needs $A$ symmetric and positive definite. If $A$ is indefinite, $\phi$ has no minimum and $u^\top Au$ can be $\le0$ (step undefined). If $A$ is not symmetric, $\nabla\phi\ne Ax-b$.
  • The fix: apply CG to the normal equations $A^\top Ax=A^\top b$. If $A$ is invertible, $A^\top A$ is symmetric positive definite and has the same solution.
Worked: 2020 P1 Q4(b)

$A_1=\begin{pmatrix}4&1&1\\1&3&2\\1&2&2\end{pmatrix}$, $A_2=\begin{pmatrix}4&1&1\\1&3&2\\1&2&1\end{pmatrix}$. Both are symmetric, so the test is positive definiteness. Sylvester's criterion: a symmetric matrix is PD exactly when all its leading minors (top-left $1\times1$, $2\times2$, … determinants) are positive.

  1. $A_1$: $4>0$, $4\cdot3-1=11>0$, $\det A_1=4(6-4)-1(2-2)+1(2-3)=7>0$ ⇒ PD: CG applies.
  2. $A_2$: $4$, $11$, $\det A_2=4(3-4)-1(1-2)+1(2-3)=-4<0$ ⇒ not PD: CG does not apply.
  3. Modification for both: run CG on $A^\top Ax=A^\top b$ (same style of algorithm, with $A^\top A$ in place of $A$).

G. The exam recipe

Recipe for "how many CG iterations?" / "compute the iterates"
  1. Check the setting: is $Q\succ0$? (Eigenvalues all positive.) If $Q$ is only PSD or indefinite, look for breakdown or unboundedness first (2016 Q4(a), 2025 Q3 with $\alpha=0$).
  2. Eigen-structure: for $\sigma I+$ rank-one pieces, apply $Q$ to each piece and to vectors perpendicular to all of them (E1). List the distinct eigenvalues and their eigenspaces.
  3. Write the start $g^{(0)}=Qx^{(0)}-h$ (or $x^{(0)}-x^*$) in those eigenspaces. Count the distinct eigenvalues it touches: that is the number of CG iterations.
  4. Justify with one line: "the Krylov space stays in the span of those eigenvectors, and $R(\lambda)=\prod(1-\lambda/\tau_j)$ vanishes on them" (or "$r$ distinct eigenvalues ⇒ at most $r$ steps").
  5. If iterates are asked: run C's five formulas; check $g^{(k+1)}\perp g^{(k)}$ and $u^{(k+1)\top}Qu^{(k)}=0$ as you go.
Traps
  • Gradients are orthogonal; directions are conjugate. Not the other way round.
  • "CG finished in 5 steps ⇒ 5 distinct eigenvalues": False. The start may touch only 5 of more (2025 T/F (i)).
  • "At most $d$ steps" needs $Q\succ0$ (and exact arithmetic).
  • In his papers $\alpha$ may be a number inside $Q$, not the step length. Read the question's letters.
  • His sign convention varies: $f=\frac12x^\top Qx-h^\top x$ (MT2) vs $+w^\top x$ (2025). Then $g^{(0)}$ at $x^{(0)}=0$ is $-h$ or $+w$.

How he asks it (from the papers)

Evidence

The CG lectures (17–24 Sep) were not recorded, so this comes from his papers and solutions.

  • The structured-matrix question is his favourite: 2016 Q4 ($uu^\top+2vv^\top$, singular) → 2025 Q3 ($\alpha I+uu^\top+2vv^\top$). Parts: eigenvalues, optimum, a degenerate case, the CG count from $x^{(0)}=0$, the iterates. Expect it again with a twist (another rank-one piece, a start that touches two eigenspaces, or $\alpha=0$).
  • The polynomial view is now standard (MT2 Q4, Q5: 20 of the 45 marks). Know the bound, the one-step $c=-2/(\lambda_{\min}+\lambda_{\max})$ trick, and "only touched eigenvalues count".
  • "State the algorithm" and "rationale for $\alpha_k$, $\beta_k$" are cheap marks (2016 Q3, MT2 Q3(a)).
  • T/F on CG facts every year: 2024 (d), 2025 (i), MT2 (a)–(e).

Practice (try on paper first, then open the answer)

Past-paper questions first, then new ones. Letters inside a past question follow that paper.

P1 MT2 2026, T/F 1(a)T/F

For a given matrix $Q\succ0$, conjugate directions are unique.

  1. (a) True
  2. (b) False
Show answer

False. Eigenvectors are one set; $Q$-Gram–Schmidt of any basis gives others (A).

P2 MT2 2026, T/F 1(b)T/F

A matrix with columns as conjugate directions has full rank.

  1. (a) True
  2. (b) False
Show answer

True (with $Q\succ0$): conjugate nonzero vectors are linearly independent (A, fact 1).

P3 MT2 2026, T/F 1(c)T/F

The Expanding Subspace theorem does not apply to arbitrary conjugate directions.

  1. (a) True
  2. (b) False
Show answer

False. It holds for any conjugate set with exact line searches (B).

P4 MT2 2026, T/F 1(d)T/F

In the CG method the conjugate directions are always descent directions.

  1. (a) True
  2. (b) False
Show answer

His key: False. But for CG with exact line search on a quadratic, every direction is a descent direction while $g^{(k)}\ne0$: $g^{(k)\top}u^{(k)}=-\|g^{(k)}\|^2<0$ (C2). So for that setting the key is arguably wrong. It does fit a wider reading: a general set of conjugate directions need not be descent directions (exact line search then just takes a negative $\alpha$), and nonlinear CG with inexact line searches can lose descent. If this sentence appears again, answer as the key does and, if space allows, write the one-line computation for the quadratic case.

P5 MT2 2026, T/F 1(e)T/F

Restarting the CG method after every 1 iteration will always lead to faster convergence.

  1. (a) True
  2. (b) False
Show answer

False. Restarting every step means $\beta=0$ always: that is steepest descent.

P6 2025 final, T/F 1(i)T/F

If a conjugate direction method applied to (CQ) finished in 5 iterations, then $Q$ has 5 distinct eigenvalues.

  1. (a) True
  2. (b) False
Show answer

False. The start may touch only 5 of more distinct eigenvalues (e.g. eigenvalues $1,\dots,6$ but the start error has no $v_6$ part). And a general conjugate direction method doesn't care about eigenvalues at all: it takes $d$ steps, so $d=5$ is another counterexample.

P7 2024 final, T/F 1(d)T/F

The Conjugate Gradient algorithm finds the global unconstrained minimum of $h(x)=\frac12x^\top Qx+b^\top x+c$ in at most $d$ iterations.

  1. (a) True
  2. (b) False
Show answer

His key: True, for $Q\succ0$ (finite termination, exact arithmetic). Strictly as written ($Q$ only symmetric) it would be false: an indefinite $Q$ has no minimum. If you have room, write "True if $Q\succ0$".

P8 MT2 2026, Q2 (5 marks)Descriptive

$A\in\mathbb R^{d\times m}$, fixed $a\in\mathbb R^d$, $g(y)=f(a+Ay)$. State the optimality condition (involving $\nabla f(a)$) and solve for $y$ if the columns $a_1,\dots,a_m$ of $A$ are $Q$-conjugate.

Show answer
  1. $\nabla_yg=A^\top\nabla f(a+Ay)=A^\top(\nabla f(a)+QAy)$; Hessian $A^\top QA\succeq0$, so $g$ is convex and the condition is $A^\top(\nabla f(a)+QAy)=0$.
  2. Conjugacy makes $A^\top QA$ diagonal: $y_i=-\dfrac{\nabla f(a)^\top a_i}{a_i^\top Qa_i}$ (B).
P9 MT2 2026, Q3 (5 marks)Descriptive

(a) In CG, $x^{(k+1)}=x^{(k)}+\alpha_ku^{(k)}$, $u^{(k+1)}=-\nabla f(x^{(k+1)})+\beta_ku^{(k)}$. What is the rationale for $\alpha_k$ and $\beta_k$? (b) $v_1,\dots,v_d$ independent. Find $A_{ij}$ so that $u_1=v_1$, $u_i=v_i-\sum_{j<i}A_{ij}u_j$ are $Q$-conjugate.

Show answer

(a) $\alpha_k$ minimises $f$ along $u^{(k)}$; $\beta_k$ makes $u^{(k+1)}$ $Q$-conjugate to $u^{(k)}$. (b) $A_{ij}=\dfrac{v_i^\top Qu_j}{u_j^\top Qu_j}$, from $u_l^\top Qu_i=v_i^\top Qu_l-A_{il}u_l^\top Qu_l=0$ (A).

P10 MT2 2026, Q4 (10 marks)Descriptive

(a) State a relation between $E(x^{(k)})$ and $E(x^{(0)})$ using the eigenvalues of $Q$. (b) Is $E(x^{(1)})\le0.3E(x^{(0)})$ if the eigenvalues are between 30 and 90? Better bound? (c) If $Q$ has 5 distinct eigenvalues, how many steps until convergence?

Show answer

(a) $E(x^{(k)})\le\max_i(1+\lambda_iP_{k-1}(\lambda_i))^2E(x^{(0)})$ for every polynomial $P_{k-1}$ of degree $k-1$. (b) True; $c=-\frac1{60}$ gives $0.25$ (worked in D). (c) $R_5(\lambda)=\prod_{j=1}^5(1-\lambda/\tau_j)$ vanishes on all eigenvalues: at most 5 steps.

P11 MT2 2026, Q5 (10 marks)Descriptive

Same setting, $x^{(0)}=0$ and $h=\alpha v_5+\beta v_9$ (eigenvectors of $Q$). (a) Compare $\mathrm{span}(g^{(0)},Qg^{(0)},\dots,Q^kg^{(0)})$ with $\mathrm{span}(v_5,v_9)$. (b) Evaluate $(x^{(0)}-x^*)^\top R_l(Q)(x^{(0)}-x^*)$. (c) Relate $E(x^{(k)})$ to $E(x^{(0)})$ and conclude.

Show answer
  1. (a) $g^{(0)}=-h\in\mathrm{span}(v_5,v_9)$, and $Q^kg^{(0)}=-\lambda_5^k\alpha v_5-\lambda_9^k\beta v_9$: the Krylov space is inside $\mathrm{span}(v_5,v_9)$.
  2. (b) $x^{(0)}-x^*=-Q^{-1}h=-\frac{\alpha}{\lambda_5}v_5-\frac\beta{\lambda_9}v_9$, so the value is $R_l(\lambda_5)\frac{\alpha^2}{\lambda_5^2}+R_l(\lambda_9)\frac{\beta^2}{\lambda_9^2}$.
  3. (c) $E(x^{(0)})=\frac12\big(\frac{\alpha^2}{\lambda_5}+\frac{\beta^2}{\lambda_9}\big)$ (the printed solution drops the $\frac12$; it cancels in the ratio). $E(x^{(k)})=\frac12\big(R_k(\lambda_5)^2\frac{\alpha^2}{\lambda_5}+R_k(\lambda_9)^2\frac{\beta^2}{\lambda_9}\big)\le\max(R_k(\lambda_5)^2,R_k(\lambda_9)^2)E(x^{(0)})$. With $R_2=(1-\frac\lambda{\lambda_5})(1-\frac\lambda{\lambda_9})$: converges in 2 steps.
P12 2016 final, Q2 (5 marks)Descriptive

$a_1,\dots,a_n\in\mathbb R^d$ ($n<d$) are linearly dependent and also $Q$-conjugate, $Q$ real symmetric. Under what conditions on $Q$ is this possible?

Show answer

Only if $Q$ is not positive definite. If $Q\succ0$, conjugate nonzero vectors are independent (proof in A). If some $a_i^\top Qa_i=0$, which needs $Q$ singular or indefinite, it can happen: $Q=\mathrm{diag}(1,0)$, $a_1=e_2$, $a_2=2e_2$.

P13 2016 final, Q3 (5 marks)Descriptive

State the conjugate gradient (CG) algorithm.

Show answer

The five formulas in section C1, with the start $u^{(0)}=-g^{(0)}$ and the stopping rule $g^{(k)}=0$. Name what $\alpha_k$ and $\beta_k$ achieve.

P14 2016 final, Q4 (10 marks)Descriptive

$Q=uu^\top+2vv^\top$, $\|u\|=\|v\|=1$, $u^\top v=0$, $f(x)=\frac12x^\top Qx+w^\top x+c$. (a) $w^\top u=w^\top v=0$: number of CG iterations from $x^{(0)}=0$? (b) What if $w=\alpha u+\beta v$ with $\alpha^2+\beta^2=1$?

Show answer

Worked in E2: (a) breakdown at the first step ($w^\top Qw=0$); $f$ is unbounded below along $-w$, so there is nothing to converge to. (b) 2 iterations if $\alpha,\beta\ne0$ (1 if one is zero), ending at $-(\alpha u+\frac\beta2v)$.

P15 2025 final, Q3 (10 marks)Descriptive

$Q=\alpha I+uu^\top+2vv^\top$, $\alpha>0$, $\|u\|=\|v\|=1$, $u^\top v=0$, $f=\frac12x^\top Qx+w^\top x+c$, $w^\top u=w^\top v=0$. (a) Eigenvalues of $Q$. (b) Global optimum point and value; the case $\alpha=0$. (c) CG from $x^{(0)}=0$: iterations and all iterates.

Show answer

Worked in E2: (a) $\alpha$ ($d-2$ times), $\alpha+1$, $\alpha+2$. (b) $x^*=-w/\alpha$, $f^*=c-\frac{\|w\|^2}{2\alpha}$; $\alpha=0$: unbounded below if $w\ne0$. (c) One iteration: $x^{(1)}=-w/\alpha$.

P16 2021 final, Part 1 Q2 (10 marks)Descriptive

$v_1^\top v_2=0$ (both nonzero), $f(x)=\frac12(x^\top v_1)^2+\alpha v_2^\top x$. (a) Hessian? Convex? (b) Global minima for all $\alpha$. (c) Repeat for $g(x)=f(x)+\frac12\|x\|^2$.

Show answer
  1. (a) $\nabla^2f=v_1v_1^\top\succeq0$ (rank one): convex, not strictly.
  2. (b) $\alpha=0$: $f\ge0$ with $f^*=0$ on the whole hyperplane $\{x:v_1^\top x=0\}$ (infinitely many minimisers). $\alpha\ne0$: $f(tv_2)=\alpha t\|v_2\|^2$ (because $v_1^\top v_2=0$) $\to-\infty$ for suitable sign of $t$: no minimum.
  3. (c) $\nabla^2g=I+v_1v_1^\top\succ0$: strictly convex. $\nabla g=v_1(v_1^\top x)+\alpha v_2+x=0$. Dot with $v_1$: $(1+\|v_1\|^2)v_1^\top x=0$, so $v_1^\top x=0$ and $x^*=-\alpha v_2$, $g^*=-\frac{\alpha^2}2\|v_2\|^2$.
P17 2020 final, Part 1 Q4 (10 marks)Descriptive

The residual form of CG for $Ax=b$ ($u^{(0)}=\mathrm{res}(x^{(0)})$, $\alpha_k=\frac{\|\mathrm{res}(x^{(k)})\|^2}{u^{(k)\top}Au^{(k)}}$, …). (a) Why does it solve the system? (b) For $A_1$, $A_2$ (section F) it applies to only one: which and why? Modify it to apply to both.

Show answer

Worked in F: (a) for symmetric PD $A$ it is CG on $\frac12x^\top Ax-b^\top x$, whose minimiser solves $Ax=b$, and $\mathrm{res}=-\nabla$; finite termination. (b) $A_1$ (PD by leading minors $4,11,7$); $A_2$ has $\det=-4$. Use $A^\top Ax=A^\top b$.

N1 New, 2025-styleDescriptive

$Q=2I+aa^\top+bb^\top$ in $\mathbb R^6$ with $a,b$ linearly independent but not orthogonal. (a) How many distinct eigenvalues can $Q$ have at most? (b) Maximum CG iterations from any start? (c) From $x^{(0)}$ with $x^{(0)}-x^*\perp a,b$?

Show answer

(a) For $w\perp a,b$: $Qw=2w$, a 4-dimensional eigenspace. $Q$ maps $\mathrm{span}\{a,b\}$ into itself and is symmetric, so the remaining two eigenvectors lie in that plane, with eigenvalues $2+\mu$ where $\mu>0$ are the eigenvalues of $aa^\top+bb^\top$ there. So at most 3 distinct eigenvalues. (b) 3. (c) The start error is in the eigenvalue-2 eigenspace: 1 step.

N2 NewDescriptive

$Q=\mathrm{diag}(2,2,5)$, $f=\frac12x^\top Qx-h^\top x$, $x^{(0)}=0$. (a) $h=(2,0,5)$: $x^*$ and the number of CG steps. (b) $h=(2,4,0)$?

Show answer

(a) $x^*=(1,0,1)$; $g^{(0)}=-h$ touches eigenvalues 2 and 5: 2 steps. (b) $g^{(0)}=-(2,4,0)$ lies in the eigenvalue-2 eigenspace: 1 step, to $x^*=(1,2,0)$.

N3 New T/FT/F

CG on $f=\frac12x^\top(5I)x-h^\top x$ converges in one iteration from any start.

  1. (a) True
  2. (b) False
Show answer

True. One distinct eigenvalue (and the first step is the steepest-descent step, which for $Q=\lambda I$ lands on $x^*$: M1, F3).

N4 New T/FT/F

The gradients produced by CG are mutually $Q$-conjugate.

  1. (a) True
  2. (b) False
Show answer

False. Gradients are mutually orthogonal; the directions are conjugate.

N5 New T/FT/F

The first CG step from $x^{(0)}$ is the same as one step of steepest descent with exact line search.

  1. (a) True
  2. (b) False
Show answer

True. $u^{(0)}=-g^{(0)}$ and $\alpha_0$ is the exact step.

N6 New T/FT/F

CG can be applied directly to $Ax=b$ for any symmetric invertible $A$.

  1. (a) True
  2. (b) False
Show answer

False. It needs positive definiteness (2020 $A_2$ is symmetric, invertible, and indefinite). Use the normal equations.

N7 New T/FT/F

After $k$ iterations from the same start, CG has a function value no larger than gradient descent with any choice of $k$ step sizes.

  1. (a) True
  2. (b) False
Show answer

True. Gradient descent's $k$-th iterate also lies in $x^{(0)}+$ the Krylov space, where CG's iterate is the best point (D1, D3).

Self-test (no looking)

S1

Define $Q$-conjugate and prove conjugate ⇒ independent (for $Q\succ0$).

Show answer

$u_i^\top Qu_j=0$, $i\ne j$. If $\sum c_ju_j=0$, multiply by $u_i^\top Q$: $c_iu_i^\top Qu_i=0$, and $u_i^\top Qu_i>0$, so $c_i=0$.

S2

Write the CG algorithm (all five update formulas).

Show answer

$\alpha_k=\frac{\|g^{(k)}\|^2}{u^{(k)\top}Qu^{(k)}}$, $x^{(k+1)}=x^{(k)}+\alpha_ku^{(k)}$, $g^{(k+1)}=g^{(k)}+\alpha_kQu^{(k)}$, $\beta_k=\frac{\|g^{(k+1)}\|^2}{\|g^{(k)}\|^2}$, $u^{(k+1)}=-g^{(k+1)}+\beta_ku^{(k)}$; start $u^{(0)}=-g^{(0)}$.

S3

State the polynomial bound and the "distinct eigenvalues" consequence.

Show answer

$E(x^{(k)})\le\max_i(1+\lambda_iP_{k-1}(\lambda_i))^2E(x^{(0)})$; with $r$ distinct eigenvalues, $R_r=\prod(1-\lambda/\tau_j)$ gives $E(x^{(r)})=0$.

S4

Eigenvalues of $5I+3pp^\top$ ($\|p\|=1$) in $\mathbb R^{10}$, and the CG count from a generic start.

Show answer

$8$ (along $p$) and $5$ (9 times): 2 distinct, so 2 steps.

S5

Best one-step bound when the eigenvalues are in $[2,8]$?

Show answer

$c=-\frac2{10}$, $\max|1+c\lambda|=0.6$, bound $0.36$.

Summary card

M2 · Conjugate gradient on one card
  • Conjugate: $u_i^\top Qu_j=0$ ($i\ne j$). With $Q\succ0$: independent, at most $d$, full rank, not unique. Without PD: can be dependent (2016 Q2).
  • Gram–Schmidt with $Q$: $u_i=v_i-\sum_{j<i}\frac{v_i^\top Qu_j}{u_j^\top Qu_j}u_j$.
  • Decoupling: $\min_yf(a+Uy)$ with conjugate columns: $y_i=-\frac{\nabla f(a)^\top u_i}{u_i^\top Qu_i}$. Conjugate direction method ⇒ at most $d$ steps.
  • Expanding Subspace: $g^{(k)}\perp u^{(i)}$ for $i<k$; $x^{(k)}$ minimises over $x^{(0)}+\mathrm{span}\{u^{(0..k-1)}\}$. Any conjugate set.
  • CG: $u^{(0)}=-g^{(0)}$; $\alpha_k=\frac{\|g^{(k)}\|^2}{u^{(k)\top}Qu^{(k)}}$; $g^{(k+1)}=g^{(k)}+\alpha_kQu^{(k)}$; $\beta_k=\frac{\|g^{(k+1)}\|^2}{\|g^{(k)}\|^2}$; $u^{(k+1)}=-g^{(k+1)}+\beta_ku^{(k)}$. Gradients orthogonal, directions conjugate, span = Krylov space.
  • Bound: $E(x^{(k)})\le\max_i(1+\lambda_iP_{k-1}(\lambda_i))^2E(x^{(0)})$. One step: $c=-\frac2{\lambda_{\min}+\lambda_{\max}}$ gives $(\frac{\lambda_{\max}-\lambda_{\min}}{\lambda_{\max}+\lambda_{\min}})^2$. General: factor $\frac{\sqrt\kappa-1}{\sqrt\kappa+1}$.
  • Count: steps = number of distinct eigenvalues touched by the start error ($\le$ number of distinct eigenvalues $\le d$).
  • Structured: $\sigma I+aa^\top+2bb^\top$ (orthonormal $a,b$): $\sigma$ ($d-2$×), $\sigma+1$, $\sigma+2$. $\sigma I+$ rank $r$ ⇒ at most $r+1$ distinct. Singular $Q$ with $w\notin$ range: unbounded below; CG breaks down ($u^\top Qu=0$) at once if $w$ is in the null space, otherwise once the range part is solved.
  • Linear systems: CG needs $A$ symmetric PD (check leading minors); otherwise use $A^\top Ax=A^\top b$.