Practice / Linear algebra

Positive-definite matrices and quadratic forms

Ten problems on positive-definite matrices: classifying 2×2 matrices by eigenvalues and by a test vector, the eigenvalue characterisation and what it says about determinants and inverses, Sylvester's criterion by completing the square, Gram matrices and ridge, a 3×3 Cholesky factorisation by hand with a solve, the gradient, Hessian and minimiser of a quadratic, Hessian PSD if and only if convex, the symmetric square root and the ellipsoid of a quadratic form, the step-size condition and convergence rate of gradient descent on a quadratic, and why a quadratic form sees only the symmetric part, with worked solutions and the mistakes that read definiteness off a determinant, trust the eigenvalues of a non-symmetric matrix, sample with the transposed Cholesky factor, assume the normal equations have a unique solution, or pick the step size from the smallest eigenvalue.

Before you start

A positive-definite matrix is one whose quadratic form is a bowl: x⊤Ax>0x^\top Ax > 0 in every direction. Every covariance matrix, every Gram matrix X⊤XX^\top X with independent columns, every Hessian at a strict minimum and every kernel matrix is one, and the properties that make them useful, a Cholesky factor, an inverse that is also positive definite, a square root, a condition number that sets the step size of gradient descent, all come from that one inequality. These ten problems classify small matrices by hand, prove the eigenvalue test and Sylvester's criterion, factor a 3×33\times3 matrix by Cholesky and solve a system with it, minimise a quadratic by completing the square, show that a convex function is exactly one with a PSD Hessian, compute a symmetric square root, derive the step size and rate of gradient descent on a quadratic, and end with the fact that a quadratic form never sees the antisymmetric part of its matrix. The five mistakes at the end are the ones that survive a glance: a positive determinant read as positive definite, positive eigenvalues of a non-symmetric matrix, the Cholesky factor used transposed, normal equations assumed solvable, and a step size chosen from the wrong eigenvalue.

  • AA is a real symmetric n×nn\times n matrix unless a problem says otherwise, II is the identity, and vectors are columns. AA is positive definite (PD, written A≻0A \succ 0) if x⊤Ax>0x^\top Ax > 0 for every x≠0x \neq 0, positive semidefinite (PSD, A⪰0A \succeq 0) if x⊤Ax≥0x^\top Ax \ge 0 for every xx, and indefinite if x⊤Axx^\top Ax takes both signs.
  • A symmetric AA has an orthonormal eigenbasis: A=QΛQ⊤A = Q\Lambda Q^\top with Q⊤Q=IQ^\top Q = I, Λ=diag⁡(λ1,…,λn)\Lambda = \operatorname{diag}(\lambda_1, \dots, \lambda_n), and Aqi=λiqiAq_i = \lambda_iq_i for the columns qiq_i of QQ (the eigenvalues page). Equivalently A=∑iλiqiqi⊤A = \sum_i\lambda_iq_iq_i^\top. λmax⁡\lambda_{\max} and λmin⁡\lambda_{\min} are the largest and smallest eigenvalues and κ=λmax⁡/λmin⁡\kappa = \lambda_{\max}/\lambda_{\min} is the condition number of a PD matrix.
  • A Cholesky factorisation of a PD matrix is A=LL⊤A = LL^\top with LL lower-triangular and Ljj>0L_{jj} > 0. Computed column by column: Ljj=Ajj−∑k<jLjk2L_{jj} = \sqrt{A_{jj} - \sum_{k<j}L_{jk}^2} and, for i>ji > j, Lij=(Aij−∑k<jLikLjk)/LjjL_{ij} = \big(A_{ij} - \sum_{k<j}L_{ik}L_{jk}\big)/L_{jj}.
  • For X∈RN×dX \in \mathbb{R}^{N\times d} the Gram matrix is X⊤XX^\top X; ∥v∥2=v⊤v\|v\|^2 = v^\top v. The singular values of XX are σi\sigma_i (the least-squares page).
  • Gradients are columns: for scalar f(x)f(x), ∇f∈Rn\nabla f \in \mathbb{R}^n and the Hessian ∇2f\nabla^2f is the n×nn\times n matrix of second partials, so for symmetric AA, ∇(x⊤Ax)=2Ax\nabla(x^\top Ax) = 2Ax and ∇(b⊤x)=b\nabla(b^\top x) = b (the matrix-calculus page). A twice-differentiable ff is convex when f(λx+(1−λ)y)≤λf(x)+(1−λ)f(y)f(\lambda x + (1 - \lambda)y) \le \lambda f(x) + (1 - \lambda)f(y) for all x,yx, y and λ∈[0,1]\lambda \in [0, 1] (the Jensen page).
  • Gradient descent with step η\eta is xk+1=xk−η∇f(xk)x_{k+1} = x_k - \eta\nabla f(x_k); ek=xk−x∗e_k = x_k - x^* is the error after kk steps.

Builds on: Eigenvalues and eigenvectors by hand, Matrix calculus conventions

Problems

  1. ·

    Classify A=[2112]A = \begin{bmatrix}2&1\\1&2\end{bmatrix}, B=[1221]B = \begin{bmatrix}1&2\\2&1\end{bmatrix} and C=[1224]C = \begin{bmatrix}1&2\\2&4\end{bmatrix} as positive definite, positive semidefinite or indefinite using their eigenvalues. For BB, exhibit a vector vv with v⊤Bv<0v^\top Bv < 0; for CC, a nonzero vector with v⊤Cv=0v^\top Cv = 0.

  2. ··

    For symmetric A=∑iλiqiqi⊤A = \sum_i\lambda_iq_iq_i^\top, show that x⊤Ax=∑iλi(qi⊤x)2x^\top Ax = \sum_i\lambda_i(q_i^\top x)^2 and hence that AA is PD if and only if every λi>0\lambda_i > 0. Deduce that a PD matrix has det⁡A>0\det A > 0 and tr⁡A>0\operatorname{tr}A > 0, is invertible, and that A−1A^{-1} is PD.

  3. ··

    By completing the square in x⊤Ax=ax2+2bxy+cy2x^\top Ax = ax^2 + 2bxy + cy^2, show that the symmetric A=[abbc]A = \begin{bmatrix}a&b\\b&c\end{bmatrix} is PD if and only if a>0a > 0 and ac−b2>0ac - b^2 > 0. For which tt is [2tt2]\begin{bmatrix}2&t\\t&2\end{bmatrix} positive definite?

  4. ··

    For X∈RN×dX \in \mathbb{R}^{N\times d}, show that X⊤XX^\top X is PSD, that it is PD if and only if the columns of XX are linearly independent, and that X⊤X+λIX^\top X + \lambda I is PD for every λ>0\lambda > 0 with eigenvalues σi2+λ\sigma_i^2 + \lambda, where the σi\sigma_i are the singular values of XX (zero for i>rank⁡Xi > \operatorname{rank}X).

  5. ··

    Compute the Cholesky factor LL of A=[422253236]A = \begin{bmatrix}4&2&2\\2&5&3\\2&3&6\end{bmatrix}, verify LL⊤=ALL^\top = A, and use it to solve Ax=bAx = b for b=(8,10,11)⊤b = (8, 10, 11)^\top by two triangular solves. What is det⁡A\det A?

  6. ··

    Let f(x)=12x⊤Ax−b⊤x+cf(x) = \tfrac12x^\top Ax - b^\top x + c with AA symmetric and PD. Compute ∇f\nabla f and ∇2f\nabla^2f, show that f(x)=12(x−x∗)⊤A(x−x∗)+f(x∗)f(x) = \tfrac12(x - x^*)^\top A(x - x^*) + f(x^*) with x∗=A−1bx^* = A^{-1}b and f(x∗)=c−12b⊤A−1bf(x^*) = c - \tfrac12b^\top A^{-1}b, and conclude that x∗x^* is the unique minimiser. Evaluate for A=[2112]A = \begin{bmatrix}2&1\\1&2\end{bmatrix}, b=(1,2)⊤b = (1, 2)^\top, c=0c = 0. What happens if AA has a negative eigenvalue?

  7. ···

    Let ff be twice differentiable on Rn\mathbb{R}^n and, for fixed xx and vv, let g(t)=f(x+tv)g(t) = f(x + tv). Show that g′′(t)=v⊤∇2f(x+tv) vg''(t) = v^\top\nabla^2f(x + tv)\,v, and use it to prove that ff is convex if and only if ∇2f(x)⪰0\nabla^2f(x) \succeq 0 for every xx. Conclude that 12x⊤Ax\tfrac12x^\top Ax is convex exactly when A⪰0A \succeq 0.

  8. ··

    For PD A=QΛQ⊤A = Q\Lambda Q^\top define A1/2=QΛ1/2Q⊤A^{1/2} = Q\Lambda^{1/2}Q^\top. Show that A1/2A^{1/2} is symmetric PD with (A1/2)2=A(A^{1/2})^2 = A, and that A−1/2AA−1/2=IA^{-1/2}AA^{-1/2} = I. Compute A1/2A^{1/2} for A=[2112]A = \begin{bmatrix}2&1\\1&2\end{bmatrix}, and describe the ellipse {x:x⊤Ax=1}\{x : x^\top Ax = 1\}.

  9. ···

    For f(x)=12x⊤Ax−b⊤xf(x) = \tfrac12x^\top Ax - b^\top x with A≻0A \succ 0, show that gradient descent satisfies ek+1=(I−ηA)eke_{k+1} = (I - \eta A)e_k, that it converges from every start if and only if 0<η<2/λmax⁡0 < \eta < 2/\lambda_{\max}, and that the error component along qiq_i shrinks by the factor ∣1−ηλi∣\lvert 1 - \eta\lambda_i\rvert per step. Find the η\eta that minimises the worst factor and the resulting rate in terms of κ\kappa. Evaluate for A=diag⁡(1,10)A = \operatorname{diag}(1, 10).

  10. ··

    For any square matrix MM, not necessarily symmetric, show that x⊤Mx=x⊤Sxx^\top Mx = x^\top Sx with S=12(M+M⊤)S = \tfrac12(M + M^\top). Show that M=[1401]M = \begin{bmatrix}1&4\\0&1\end{bmatrix} has both eigenvalues equal to 11 and yet v⊤Mv<0v^\top Mv < 0 for some vv. Why does the eigenvalue test of Problem 2 not apply?

Worked solutions

Problem 1

Classify A=[2112]A = \begin{bmatrix}2&1\\1&2\end{bmatrix}, B=[1221]B = \begin{bmatrix}1&2\\2&1\end{bmatrix} and C=[1224]C = \begin{bmatrix}1&2\\2&4\end{bmatrix} as positive definite, positive semidefinite or indefinite using their eigenvalues. For BB, exhibit a vector vv with v⊤Bv<0v^\top Bv < 0; for CC, a nonzero vector with v⊤Cv=0v^\top Cv = 0.

  1. AA: det⁡(A−λI)=(2−λ)2−1=0\det(A - \lambda I) = (2 - \lambda)^2 - 1 = 0 gives λ=3,1\lambda = 3, 1, both positive: PD.The eigenvalues page's Problem 1; Problem 2 below shows why positive eigenvalues mean PD.
  2. BB: (1−λ)2−4=0(1 - \lambda)^2 - 4 = 0 gives 1−λ=±21 - \lambda = \pm 2, λ=3,−1\lambda = 3, -1: indefinite.One eigenvalue of each sign.
  3. v=(1,−1)⊤v = (1, -1)^\top: v⊤Bv=1−2−2+1=−2<0v^\top Bv = 1 - 2 - 2 + 1 = -2 < 0.vv is the eigenvector for λ=−1\lambda = -1, since B(1,−1)⊤=(1−2,2−1)⊤=−(1,−1)⊤B(1, -1)^\top = (1 - 2, 2 - 1)^\top = -(1, -1)^\top; its quadratic form is λ∥v∥2=−2\lambda\|v\|^2 = -2.
  4. CC: (1−λ)(4−λ)−4=λ2−5λ=0(1 - \lambda)(4 - \lambda) - 4 = \lambda^2 - 5\lambda = 0 gives λ=5,0\lambda = 5, 0: PSD but not PD.A zero eigenvalue means x⊤Cx=0x^\top Cx = 0 for a nonzero xx, so the form is never negative but is not always positive.
  5. v=(2,−1)⊤v = (2, -1)^\top: Cv=(2−2,4−4)⊤=0Cv = (2 - 2, 4 - 4)^\top = 0, so v⊤Cv=0v^\top Cv = 0.The null vector of CC; CC has rank one, C=(1,2)⊤(1,2)C = (1, 2)^\top(1, 2).
  6. A≻0A \succ 0 (eigenvalues 3,13, 1); BB indefinite (eigenvalues 3,−13, -1, v=(1,−1)⊤v = (1, -1)^\top gives −2-2); C⪰0C \succeq 0 but not PD (eigenvalues 5,05, 0, v=(2,−1)⊤v = (2, -1)^\top gives 00)All three have positive diagonal entries and positive trace, and BB even has all entries positive, so none of those tests decides anything; BB's determinant is −3-3 and CC's is 00, which rule them out, but a positive determinant would not have ruled them in (Mistake 1). AA is the covariance matrix of the Gaussian page's Problem 1, and CC is what a covariance looks like when one coordinate is twice the other.

Problem 2

For symmetric A=∑iλiqiqi⊤A = \sum_i\lambda_iq_iq_i^\top, show that x⊤Ax=∑iλi(qi⊤x)2x^\top Ax = \sum_i\lambda_i(q_i^\top x)^2 and hence that AA is PD if and only if every λi>0\lambda_i > 0. Deduce that a PD matrix has det⁡A>0\det A > 0 and tr⁡A>0\operatorname{tr}A > 0, is invertible, and that A−1A^{-1} is PD.

  1. x⊤Ax=x⊤(∑iλiqiqi⊤)x=∑iλi(x⊤qi)(qi⊤x)=∑iλi(qi⊤x)2x^\top Ax = x^\top\Big(\sum_i\lambda_iq_iq_i^\top\Big)x = \sum_i\lambda_i(x^\top q_i)(q_i^\top x) = \sum_i\lambda_i(q_i^\top x)^2.Distribute x⊤x^\top and xx over the sum; x⊤qi=qi⊤xx^\top q_i = q_i^\top x is a scalar.
  2. If every λi>0\lambda_i > 0 and x≠0x \neq 0, then some qi⊤x≠0q_i^\top x \neq 0, so x⊤Ax>0x^\top Ax > 0.The qiq_i are an orthonormal basis, so x=∑i(qi⊤x)qix = \sum_i(q_i^\top x)q_i; if every coefficient were zero, xx would be zero. All terms are ≥0\ge 0 and at least one is >0> 0.
  3. If AA is PD, then λi=qi⊤Aqi>0\lambda_i = q_i^\top Aq_i > 0 for every ii.Take x=qix = q_i in the definition: qi⊤Aqi=qi⊤(λiqi)=λi∥qi∥2=λiq_i^\top Aq_i = q_i^\top(\lambda_iq_i) = \lambda_i\|q_i\|^2 = \lambda_i.
  4. det⁡A=∏iλi>0\det A = \prod_i\lambda_i > 0 and tr⁡A=∑iλi>0\operatorname{tr}A = \sum_i\lambda_i > 0; no eigenvalue is zero, so AA is invertible.The eigenvalues page's Problem 5, extended to n×nn\times n by det⁡(QΛQ⊤)=det⁡Λ\det(Q\Lambda Q^\top) = \det\Lambda and tr⁡(QΛQ⊤)=tr⁡(ΛQ⊤Q)=tr⁡Λ\operatorname{tr}(Q\Lambda Q^\top) = \operatorname{tr}(\Lambda Q^\top Q) = \operatorname{tr}\Lambda; a matrix is singular exactly when 00 is an eigenvalue.
  5. A−1=QΛ−1Q⊤=∑i1λiqiqi⊤A^{-1} = Q\Lambda^{-1}Q^\top = \sum_i\dfrac1{\lambda_i}q_iq_i^\top, with every 1/λi>01/\lambda_i > 0, so A−1A^{-1} is PD by step 2.(QΛQ⊤)(QΛ−1Q⊤)=QΛΛ−1Q⊤=I(Q\Lambda Q^\top)(Q\Lambda^{-1}Q^\top) = Q\Lambda\Lambda^{-1}Q^\top = I because Q⊤Q=IQ^\top Q = I; the inverse has the same eigenvectors and reciprocal eigenvalues.
  6. x⊤Ax=∑iλi(qi⊤x)2x^\top Ax = \sum_i\lambda_i(q_i^\top x)^2; A≻0  ⟺  A \succ 0 \iff all λi>0\lambda_i > 0; then det⁡A>0\det A > 0, tr⁡A>0\operatorname{tr}A > 0, AA is invertible and A−1≻0A^{-1} \succ 0In the eigenbasis the quadratic form is a weighted sum of squares, and definiteness is the sign pattern of the weights: all >0> 0 is PD, all ≥0\ge 0 is PSD, mixed is indefinite. The converses of step 4 fail: det⁡>0\det > 0 and tr⁡>0\operatorname{tr} > 0 together do not give PD in three dimensions (diag⁡(4,−1,−1)\operatorname{diag}(4, -1, -1)), and in two dimensions they do only because two eigenvalues with positive product and positive sum are both positive, which is Problem 3's criterion. Step 5 is why the precision matrix Σ−1\Sigma^{-1} of a Gaussian is PD whenever the covariance is.

Problem 3

By completing the square in x⊤Ax=ax2+2bxy+cy2x^\top Ax = ax^2 + 2bxy + cy^2, show that the symmetric A=[abbc]A = \begin{bmatrix}a&b\\b&c\end{bmatrix} is PD if and only if a>0a > 0 and ac−b2>0ac - b^2 > 0. For which tt is [2tt2]\begin{bmatrix}2&t\\t&2\end{bmatrix} positive definite?

  1. For a≠0a \neq 0: ax2+2bxy+cy2=a(x+bay)2+(c−b2a)y2=a(x+bay)2+ac−b2ay2ax^2 + 2bxy + cy^2 = a\Big(x + \dfrac bay\Big)^2 + \Big(c - \dfrac{b^2}a\Big)y^2 = a\Big(x + \dfrac bay\Big)^2 + \dfrac{ac - b^2}{a}y^2.Expand a(x+bay)2=ax2+2bxy+b2ay2a(x + \tfrac bay)^2 = ax^2 + 2bxy + \tfrac{b^2}ay^2 and subtract the extra b2ay2\tfrac{b^2}ay^2.
  2. If a>0a > 0 and ac−b2>0ac - b^2 > 0: both coefficients are positive, so the form is ≥0\ge 0, and it is 00 only when y=0y = 0 and then x+bay=x=0x + \tfrac bay = x = 0.A positive combination of two squares vanishes only when both squares vanish.
  3. If AA is PD: x=(1,0)⊤x = (1, 0)^\top gives a>0a > 0, and x=(−ba,1)⊤x = (-\tfrac ba, 1)^\top gives ac−b2a>0\dfrac{ac - b^2}{a} > 0, so ac−b2>0ac - b^2 > 0.Two test vectors, chosen to kill one square each in step 1; a>0a > 0 lets the inequality be multiplied through.
  4. [2tt2]\begin{bmatrix}2&t\\t&2\end{bmatrix}: a=2>0a = 2 > 0 and ac−b2=4−t2>0ac - b^2 = 4 - t^2 > 0 exactly when ∣t∣<2\lvert t\rvert < 2.Step 2 with a=c=2a = c = 2, b=tb = t.
  5. [abbc]≻0  ⟺  a>0\begin{bmatrix}a&b\\b&c\end{bmatrix} \succ 0 \iff a > 0 and ac−b2>0ac - b^2 > 0; [2tt2]≻0  ⟺  ∣t∣<2\begin{bmatrix}2&t\\t&2\end{bmatrix} \succ 0 \iff \lvert t\rvert < 2This is Sylvester's criterion: all leading principal minors positive, the 1×11\times1 minor aa and the 2×22\times2 minor det⁡A\det A. Completing the square is the 2×22\times2 Cholesky factorisation in disguise, L=[a0b/a(ac−b2)/a]L = \begin{bmatrix}\sqrt a&0\\b/\sqrt a&\sqrt{(ac - b^2)/a}\end{bmatrix}, and the criterion fails exactly where a square root in Problem 5's algorithm would go negative. At t=±2t = \pm 2 the matrix is PSD with the null vector (1,∓1)⊤(1, \mp 1)^\top, and for ∣t∣>2\lvert t\rvert > 2 it is indefinite despite its positive diagonal and positive trace. For a covariance [σ12ρσ1σ2ρσ1σ2σ22]\begin{bmatrix}\sigma_1^2&\rho\sigma_1\sigma_2\\\rho\sigma_1\sigma_2&\sigma_2^2\end{bmatrix} the condition is ρ2<1\rho^2 < 1.

Problem 4

For X∈RN×dX \in \mathbb{R}^{N\times d}, show that X⊤XX^\top X is PSD, that it is PD if and only if the columns of XX are linearly independent, and that X⊤X+λIX^\top X + \lambda I is PD for every λ>0\lambda > 0 with eigenvalues σi2+λ\sigma_i^2 + \lambda, where the σi\sigma_i are the singular values of XX (zero for i>rank⁡Xi > \operatorname{rank}X).

  1. v⊤X⊤Xv=(Xv)⊤(Xv)=∥Xv∥2≥0v^\top X^\top Xv = (Xv)^\top(Xv) = \|Xv\|^2 \ge 0.Group the product as (Xv)⊤(Xv)(Xv)^\top(Xv); a squared norm is nonnegative.
  2. v⊤X⊤Xv=0  ⟺  Xv=0v^\top X^\top Xv = 0 \iff Xv = 0.A norm is zero only for the zero vector.
  3. X⊤X≻0  ⟺  Xv≠0X^\top X \succ 0 \iff Xv \neq 0 for every v≠0  ⟺  v \neq 0 \iff the columns of XX are linearly independent.Xv=∑jvjxjXv = \sum_jv_jx_j with xjx_j the columns, and Xv=0Xv = 0 for some v≠0v \neq 0 is exactly a linear dependence among them. That needs N≥dN \ge d; with N<dN < d some nonzero vv always has Xv=0Xv = 0.
  4. v⊤(X⊤X+λI)v=∥Xv∥2+λ∥v∥2>0v^\top(X^\top X + \lambda I)v = \|Xv\|^2 + \lambda\|v\|^2 > 0 for v≠0v \neq 0.Step 1 plus λ∥v∥2>0\lambda\|v\|^2 > 0; the second term is positive even when the first is zero.
  5. With X=UΣV⊤X = U\Sigma V^\top: X⊤X=VΣ⊤ΣV⊤X^\top X = V\Sigma^\top\Sigma V^\top, so its eigenvalues are σi2\sigma_i^2 with eigenvectors the right singular vectors viv_i, and (X⊤X+λI)vi=(σi2+λ)vi(X^\top X + \lambda I)v_i = (\sigma_i^2 + \lambda)v_i.U⊤U=IU^\top U = I and Σ⊤Σ\Sigma^\top\Sigma is diagonal with entries σi2\sigma_i^2 (the least-squares page); adding λI\lambda I adds λ\lambda to every eigenvalue without moving the eigenvectors.
  6. X⊤X⪰0X^\top X \succeq 0 always; X⊤X≻0  ⟺  rank⁡X=dX^\top X \succ 0 \iff \operatorname{rank}X = d; X⊤X+λI≻0X^\top X + \lambda I \succ 0 for λ>0\lambda > 0, with eigenvalues σi2+λ\sigma_i^2 + \lambdaEvery Gram matrix, covariance matrix (1N−1X⊤HX\tfrac1{N-1}X^\top HX on the variance page) and kernel matrix is PSD for the reason in step 1, and PD only when nothing is collinear. The normal equations X⊤Xw=X⊤yX^\top Xw = X^\top y have a unique solution exactly in the PD case (Mistake 4); ridge regression's X⊤X+λIX^\top X + \lambda I is always invertible, with condition number (σmax⁡2+λ)/(σmin⁡2+λ)(\sigma_{\max}^2 + \lambda)/(\sigma_{\min}^2 + \lambda), which λ\lambda pulls towards 11, and that is what makes ridge both solvable and well-conditioned. The bias–variance page prices the shrinkage this costs.

Problem 5

Compute the Cholesky factor LL of A=[422253236]A = \begin{bmatrix}4&2&2\\2&5&3\\2&3&6\end{bmatrix}, verify LL⊤=ALL^\top = A, and use it to solve Ax=bAx = b for b=(8,10,11)⊤b = (8, 10, 11)^\top by two triangular solves. What is det⁡A\det A?

  1. Column 1: L11=A11=2L_{11} = \sqrt{A_{11}} = 2, L21=A21/L11=1L_{21} = A_{21}/L_{11} = 1, L31=A31/L11=1L_{31} = A_{31}/L_{11} = 1.The algorithm with no earlier columns to subtract.
  2. Column 2: L22=A22−L212=5−1=2L_{22} = \sqrt{A_{22} - L_{21}^2} = \sqrt{5 - 1} = 2, L32=(A32−L31L21)/L22=(3−1)/2=1L_{32} = (A_{32} - L_{31}L_{21})/L_{22} = (3 - 1)/2 = 1.Subtract the contribution of column 1 before taking the root and dividing.
  3. Column 3: L33=A33−L312−L322=6−1−1=2L_{33} = \sqrt{A_{33} - L_{31}^2 - L_{32}^2} = \sqrt{6 - 1 - 1} = 2.Both earlier columns contribute to the (3,3)(3, 3) entry.
  4. L=[200120112]L = \begin{bmatrix}2&0&0\\1&2&0\\1&1&2\end{bmatrix} and LL⊤=[42221+41+221+21+1+4]=ALL^\top = \begin{bmatrix}4&2&2\\2&1 + 4&1 + 2\\2&1 + 2&1 + 1 + 4\end{bmatrix} = A.Entry (i,j)(i, j) of LL⊤LL^\top is the dot product of rows ii and jj of LL.
  5. Forward solve Ly=bLy = b: y1=8/2=4y_1 = 8/2 = 4, y2=(10−1⋅4)/2=3y_2 = (10 - 1\cdot 4)/2 = 3, y3=(11−1⋅4−1⋅3)/2=2y_3 = (11 - 1\cdot 4 - 1\cdot 3)/2 = 2.Row by row from the top; each row has one new unknown.
  6. Back solve L⊤x=yL^\top x = y: x3=2/2=1x_3 = 2/2 = 1, x2=(3−1⋅1)/2=1x_2 = (3 - 1\cdot 1)/2 = 1, x1=(4−1⋅1−1⋅1)/2=1x_1 = (4 - 1\cdot 1 - 1\cdot 1)/2 = 1.L⊤L^\top is upper-triangular, so solve from the bottom; Ax=LL⊤x=Ly=bAx = LL^\top x = Ly = b.
  7. det⁡A=det⁡L det⁡L⊤=(det⁡L)2=(2⋅2⋅2)2=64\det A = \det L\,\det L^\top = (\det L)^2 = (2\cdot 2\cdot 2)^2 = 64.The determinant of a triangular matrix is the product of its diagonal, and det⁡L⊤=det⁡L\det L^\top = \det L.
  8. L=[200120112]L = \begin{bmatrix}2&0&0\\1&2&0\\1&1&2\end{bmatrix}, LL⊤=ALL^\top = A; x=(1,1,1)⊤x = (1, 1, 1)^\top; det⁡A=64\det A = 64Check: A(1,1,1)⊤=(8,10,11)⊤A(1, 1, 1)^\top = (8, 10, 11)^\top. The three square roots were of 44, 44 and 44, all positive, which is the proof that AA is PD: Cholesky succeeds exactly when every pivot Ajj−∑k<jLjk2A_{jj} - \sum_{k<j}L_{jk}^2 is positive, and it is how software tests definiteness, at a third of the cost of an eigendecomposition. The Gaussian page uses LL to sample, x=μ+Lεx = \mu + L\varepsilon (and not L⊤εL^\top\varepsilon, Mistake 3), and log⁡det⁡Σ=2∑jlog⁡Ljj\log\det\Sigma = 2\sum_j\log L_{jj} is how its normaliser is computed without forming the determinant.

Problem 6

Let f(x)=12x⊤Ax−b⊤x+cf(x) = \tfrac12x^\top Ax - b^\top x + c with AA symmetric and PD. Compute ∇f\nabla f and ∇2f\nabla^2f, show that f(x)=12(x−x∗)⊤A(x−x∗)+f(x∗)f(x) = \tfrac12(x - x^*)^\top A(x - x^*) + f(x^*) with x∗=A−1bx^* = A^{-1}b and f(x∗)=c−12b⊤A−1bf(x^*) = c - \tfrac12b^\top A^{-1}b, and conclude that x∗x^* is the unique minimiser. Evaluate for A=[2112]A = \begin{bmatrix}2&1\\1&2\end{bmatrix}, b=(1,2)⊤b = (1, 2)^\top, c=0c = 0. What happens if AA has a negative eigenvalue?

  1. ∇f=Ax−b\nabla f = Ax - b and ∇2f=A\nabla^2f = A.∇(12x⊤Ax)=Ax\nabla(\tfrac12x^\top Ax) = Ax for symmetric AA and ∇(b⊤x)=b\nabla(b^\top x) = b (the matrix-calculus page); the Hessian is the Jacobian of Ax−bAx - b.
  2. 12(x−x∗)⊤A(x−x∗)=12x⊤Ax−x⊤Ax∗+12x∗⊤Ax∗\tfrac12(x - x^*)^\top A(x - x^*) = \tfrac12x^\top Ax - x^\top Ax^* + \tfrac12x^{*\top}Ax^*.Expand; the two cross terms are equal because AA is symmetric.
  3. With Ax∗=bAx^* = b: x⊤Ax∗=b⊤xx^\top Ax^* = b^\top x and x∗⊤Ax∗=b⊤A−1bx^{*\top}Ax^* = b^\top A^{-1}b, so 12(x−x∗)⊤A(x−x∗)=12x⊤Ax−b⊤x+12b⊤A−1b=f(x)−c+12b⊤A−1b\tfrac12(x - x^*)^\top A(x - x^*) = \tfrac12x^\top Ax - b^\top x + \tfrac12b^\top A^{-1}b = f(x) - c + \tfrac12b^\top A^{-1}b.Substitute Ax∗=bAx^* = b and x∗=A−1bx^* = A^{-1}b; compare with the definition of ff.
  4. f(x)=12(x−x∗)⊤A(x−x∗)+f(x∗)f(x) = \tfrac12(x - x^*)^\top A(x - x^*) + f(x^*) with f(x∗)=c−12b⊤A−1bf(x^*) = c - \tfrac12b^\top A^{-1}b; the first term is >0> 0 for x≠x∗x \neq x^* and 00 at x∗x^*.Rearrange step 3; A≻0A \succ 0 applied to the vector x−x∗x - x^*.
  5. A−1=13[2−1−12]A^{-1} = \tfrac13\begin{bmatrix}2&-1\\-1&2\end{bmatrix}, x∗=13(2−2,−1+4)⊤=(0,1)⊤x^* = \tfrac13(2 - 2, -1 + 4)^\top = (0, 1)^\top, f(x∗)=−12b⊤x∗=−12(0+2)=−1f(x^*) = -\tfrac12b^\top x^* = -\tfrac12(0 + 2) = -1.The 2×22\times2 inverse with det⁡A=3\det A = 3; b⊤A−1b=b⊤x∗b^\top A^{-1}b = b^\top x^*. Check: f(0,1)=12⋅2−2=−1f(0, 1) = \tfrac12\cdot 2 - 2 = -1 and ∇f(0,1)=(1,2)⊤−(1,2)⊤=0\nabla f(0, 1) = (1, 2)^\top - (1, 2)^\top = 0.
  6. If Av=λvAv = \lambda v with λ<0\lambda < 0: f(tv)=12λt2∥v∥2−t b⊤v+c→−∞f(tv) = \tfrac12\lambda t^2\|v\|^2 - t\,b^\top v + c \to -\infty as t→∞t \to \infty.Along an eigenvector the quadratic term is 12λt2∥v∥2\tfrac12\lambda t^2\|v\|^2, and a negative quadratic beats a linear term for large tt.
  7. ∇f=Ax−b\nabla f = Ax - b, ∇2f=A\nabla^2f = A; f(x)=12(x−x∗)⊤A(x−x∗)+f(x∗)f(x) = \tfrac12(x - x^*)^\top A(x - x^*) + f(x^*) with x∗=A−1bx^* = A^{-1}b and f(x∗)=c−12b⊤A−1bf(x^*) = c - \tfrac12b^\top A^{-1}b, the unique minimiser; for the example x∗=(0,1)⊤x^* = (0, 1)^\top, f(x∗)=−1f(x^*) = -1; with a negative eigenvalue ff is unbounded belowCompleting the square in nn dimensions: the bowl is centred at x∗x^* and shaped by AA. Setting ∇f=0\nabla f = 0 finds the same x∗x^*, but only step 4 says it is a minimum rather than a saddle, and only PD makes it unique: a PSD AA with Av=0Av = 0 leaves ff constant along vv (a valley of minimisers if b⊥vb \perp v, no minimiser at all otherwise), which is Mistake 4 in the least-squares setting. Newton's method is exactly this calculation applied to the quadratic model of a general ff, which the Newton page takes up.

Problem 7

Let ff be twice differentiable on Rn\mathbb{R}^n and, for fixed xx and vv, let g(t)=f(x+tv)g(t) = f(x + tv). Show that g′′(t)=v⊤∇2f(x+tv) vg''(t) = v^\top\nabla^2f(x + tv)\,v, and use it to prove that ff is convex if and only if ∇2f(x)⪰0\nabla^2f(x) \succeq 0 for every xx. Conclude that 12x⊤Ax\tfrac12x^\top Ax is convex exactly when A⪰0A \succeq 0.

  1. g′(t)=∇f(x+tv)⊤vg'(t) = \nabla f(x + tv)^\top v.Chain rule: the derivative of ff along the curve x+tvx + tv, whose velocity is vv (the Jacobians page).
  2. g′′(t)=v⊤∇2f(x+tv) vg''(t) = v^\top\nabla^2f(x + tv)\,v.Differentiate ∑i∂if(x+tv) vi\sum_i\partial_if(x + tv)\,v_i again: each ∂if\partial_if contributes ∑j∂ijf vj\sum_j\partial_{ij}f\,v_j, giving ∑ijvi ∂ijf vj\sum_{ij}v_i\,\partial_{ij}f\,v_j.
  3. If ∇2f⪰0\nabla^2f \succeq 0 everywhere, then g′′≥0g'' \ge 0 for every x,vx, v, so each gg is convex: f(λy+(1−λ)z)=g(λ)f(\lambda y + (1 - \lambda)z) = g(\lambda) with x=zx = z, v=y−zv = y - z, and g(λ)=g(λ⋅1+(1−λ)⋅0)≤λg(1)+(1−λ)g(0)=λf(y)+(1−λ)f(z)g(\lambda) = g(\lambda\cdot 1 + (1 - \lambda)\cdot 0) \le \lambda g(1) + (1 - \lambda)g(0) = \lambda f(y) + (1 - \lambda)f(z).The Jensen page's Problem 2: a one-variable function with nonnegative second derivative is convex; the segment from zz to yy is the line z+t(y−z)z + t(y - z) for t∈[0,1]t \in [0, 1].
  4. Conversely, if ff is convex then every gg is convex, so g′′(0)≥0g''(0) \ge 0, that is v⊤∇2f(x) v≥0v^\top\nabla^2f(x)\,v \ge 0 for every vv.Restricting a convex function to a line keeps the chord inequality, and a convex twice-differentiable function of one variable has g′′≥0g'' \ge 0: if g′′(0)<0g''(0) < 0 then g(h)+g(−h)−2g(0)=g′′(0)h2+o(h2)<0g(h) + g(-h) - 2g(0) = g''(0)h^2 + o(h^2) < 0 for small hh, contradicting the midpoint chord inequality.
  5. f(x)=12x⊤Axf(x) = \tfrac12x^\top Ax has ∇2f=A\nabla^2f = A at every xx, so ff is convex exactly when A⪰0A \succeq 0.Problem 6, step 1; the Hessian is constant.
  6. g′′(t)=v⊤∇2f(x+tv) vg''(t) = v^\top\nabla^2f(x + tv)\,v; ff convex   ⟺  ∇2f(x)⪰0\iff \nabla^2f(x) \succeq 0 for all xx; 12x⊤Ax\tfrac12x^\top Ax convex   ⟺  A⪰0\iff A \succeq 0Convexity in nn dimensions is convexity along every line, and the second derivative along a line is the Hessian's quadratic form in that direction, so PSD everywhere is the whole story. It has to be everywhere (the Jensen page's Mistake 5) and PSD is enough: PD gives strict convexity, but the converse fails (x4x^4 is strictly convex with f′′(0)=0f''(0) = 0). This is the test that certifies least squares (Hessian 2X⊤X2X^\top X, Problem 4), ridge, logistic regression (Hessian 1NX⊤DX\tfrac1NX^\top DX on the Hessians page) and cross-entropy with softmax (the Jensen page's Problem 7) as convex, and it is what a neural network with a hidden layer fails.

Problem 8

For PD A=QΛQ⊤A = Q\Lambda Q^\top define A1/2=QΛ1/2Q⊤A^{1/2} = Q\Lambda^{1/2}Q^\top. Show that A1/2A^{1/2} is symmetric PD with (A1/2)2=A(A^{1/2})^2 = A, and that A−1/2AA−1/2=IA^{-1/2}AA^{-1/2} = I. Compute A1/2A^{1/2} for A=[2112]A = \begin{bmatrix}2&1\\1&2\end{bmatrix}, and describe the ellipse {x:x⊤Ax=1}\{x : x^\top Ax = 1\}.

  1. (A1/2)⊤=QΛ1/2Q⊤=A1/2(A^{1/2})^\top = Q\Lambda^{1/2}Q^\top = A^{1/2}, and its eigenvalues λi\sqrt{\lambda_i} are positive, so A1/2≻0A^{1/2} \succ 0.Λ1/2\Lambda^{1/2} is diagonal, hence symmetric; Problem 2's test.
  2. (A1/2)2=QΛ1/2Q⊤QΛ1/2Q⊤=QΛQ⊤=A(A^{1/2})^2 = Q\Lambda^{1/2}Q^\top Q\Lambda^{1/2}Q^\top = Q\Lambda Q^\top = A.Q⊤Q=IQ^\top Q = I in the middle and Λ1/2Λ1/2=Λ\Lambda^{1/2}\Lambda^{1/2} = \Lambda.
  3. A−1/2=QΛ−1/2Q⊤A^{-1/2} = Q\Lambda^{-1/2}Q^\top and A−1/2AA−1/2=QΛ−1/2ΛΛ−1/2Q⊤=QQ⊤=IA^{-1/2}AA^{-1/2} = Q\Lambda^{-1/2}\Lambda\Lambda^{-1/2}Q^\top = QQ^\top = I.The same cancellation; Λ−1/2ΛΛ−1/2=I\Lambda^{-1/2}\Lambda\Lambda^{-1/2} = I entrywise, and QQ⊤=IQQ^\top = I for a square orthogonal matrix.
  4. For the example, Q=12[111−1]Q = \dfrac1{\sqrt2}\begin{bmatrix}1&1\\1&-1\end{bmatrix}, Λ=diag⁡(3,1)\Lambda = \operatorname{diag}(3, 1), so A1/2=3 q1q1⊤+1⋅q2q2⊤=32[1111]+12[1−1−11]=12[3+13−13−13+1]A^{1/2} = \sqrt3\,q_1q_1^\top + 1\cdot q_2q_2^\top = \dfrac{\sqrt3}2\begin{bmatrix}1&1\\1&1\end{bmatrix} + \dfrac12\begin{bmatrix}1&-1\\-1&1\end{bmatrix} = \dfrac12\begin{bmatrix}\sqrt3 + 1&\sqrt3 - 1\\\sqrt3 - 1&\sqrt3 + 1\end{bmatrix}.The eigenvalues page's Problem 8 for QQ and Λ\Lambda; A1/2=∑iλi qiqi⊤A^{1/2} = \sum_i\sqrt{\lambda_i}\,q_iq_i^\top with q1=(1,1)⊤/2q_1 = (1, 1)^\top/\sqrt2 and q2=(1,−1)⊤/2q_2 = (1, -1)^\top/\sqrt2.
  5. Check: (A1/2)2\big(A^{1/2}\big)^2 has diagonal 14((3+1)2+(3−1)2)=14(8)=2\tfrac14\big((\sqrt3 + 1)^2 + (\sqrt3 - 1)^2\big) = \tfrac14(8) = 2 and off-diagonal 14⋅2(3+1)(3−1)=14⋅4=1\tfrac14\cdot 2(\sqrt3 + 1)(\sqrt3 - 1) = \tfrac14\cdot 4 = 1.(3±1)2=4±23(\sqrt3 \pm 1)^2 = 4 \pm 2\sqrt3 and (3+1)(3−1)=2(\sqrt3 + 1)(\sqrt3 - 1) = 2.
  6. With y=Q⊤xy = Q^\top x: x⊤Ax=y⊤Λy=3y12+y22=1x^\top Ax = y^\top\Lambda y = 3y_1^2 + y_2^2 = 1, an ellipse with semi-axis 1/31/\sqrt3 along q1q_1 and 11 along q2q_2.Problem 2's sum of squares in the eigenbasis; λiyi2=1\lambda_iy_i^2 = 1 on the axis gives yi=1/λiy_i = 1/\sqrt{\lambda_i}.
  7. A1/2=QΛ1/2Q⊤≻0A^{1/2} = Q\Lambda^{1/2}Q^\top \succ 0 with (A1/2)2=A(A^{1/2})^2 = A and A−1/2AA−1/2=IA^{-1/2}AA^{-1/2} = I; for the example A1/2=12[3+13−13−13+1]A^{1/2} = \tfrac12\begin{bmatrix}\sqrt3 + 1&\sqrt3 - 1\\\sqrt3 - 1&\sqrt3 + 1\end{bmatrix}; x⊤Ax=1x^\top Ax = 1 is an ellipse with semi-axes 1/31/\sqrt3 along (1,1)⊤/2(1, 1)^\top/\sqrt2 and 11 along (1,−1)⊤/2(1, -1)^\top/\sqrt2A PD matrix has two useful square roots: the symmetric A1/2A^{1/2} here and the triangular Cholesky LL of Problem 5, with A=A1/2A1/2=LL⊤A = A^{1/2}A^{1/2} = LL^\top. Either one turns N(0,I)\mathcal{N}(0, I) into N(0,A)\mathcal{N}(0, A) by multiplication, and either inverse whitens, which is the variance page's W=Λ−1/2Q⊤W = \Lambda^{-1/2}Q^\top up to a rotation. The ellipse is the unit ball of the norm ∥x∥A=x⊤Ax\|x\|_A = \sqrt{x^\top Ax} and the level set of the Gaussian with precision AA: long axes where the eigenvalue is small, and Problem 9 shows that the ratio of its axes, κ\sqrt\kappa, is what slows gradient descent.

Problem 9

For f(x)=12x⊤Ax−b⊤xf(x) = \tfrac12x^\top Ax - b^\top x with A≻0A \succ 0, show that gradient descent satisfies ek+1=(I−ηA)eke_{k+1} = (I - \eta A)e_k, that it converges from every start if and only if 0<η<2/λmax⁡0 < \eta < 2/\lambda_{\max}, and that the error component along qiq_i shrinks by the factor ∣1−ηλi∣\lvert 1 - \eta\lambda_i\rvert per step. Find the η\eta that minimises the worst factor and the resulting rate in terms of κ\kappa. Evaluate for A=diag⁡(1,10)A = \operatorname{diag}(1, 10).

  1. xk+1−x∗=xk−η(Axk−b)−x∗=(xk−x∗)−ηA(xk−x∗)x_{k+1} - x^* = x_k - \eta(Ax_k - b) - x^* = (x_k - x^*) - \eta A(x_k - x^*), so ek+1=(I−ηA)eke_{k+1} = (I - \eta A)e_k.∇f=Ax−b\nabla f = Ax - b (Problem 6) and b=Ax∗b = Ax^*, so Axk−b=A(xk−x∗)Ax_k - b = A(x_k - x^*).
  2. With ek=∑ici(k)qie_k = \sum_ic_i^{(k)}q_i: ci(k+1)=(1−ηλi)ci(k)c_i^{(k+1)} = (1 - \eta\lambda_i)c_i^{(k)}, so ci(k)=(1−ηλi)kci(0)c_i^{(k)} = (1 - \eta\lambda_i)^kc_i^{(0)}.(I−ηA)qi=qi−ηλiqi(I - \eta A)q_i = q_i - \eta\lambda_iq_i; the eigenvectors decouple the iteration into nn scalar recurrences.
  3. ek→0e_k \to 0 for every e0e_0   ⟺  ∣1−ηλi∣<1\iff \lvert 1 - \eta\lambda_i\rvert < 1 for every ii   ⟺  0<ηλi<2\iff 0 < \eta\lambda_i < 2 for every ii   ⟺  0<η<2/λmax⁡\iff 0 < \eta < 2/\lambda_{\max}.A geometric sequence tends to zero exactly when its ratio has modulus below 11; the binding constraint is the largest eigenvalue, since ηλi<2\eta\lambda_i < 2 for all ii is ηλmax⁡<2\eta\lambda_{\max} < 2, and η>0\eta > 0 is needed for λmin⁡\lambda_{\min}.
  4. The worst factor is ρ(η)=max⁡i∣1−ηλi∣=max⁡(1−ηλmin⁡, ηλmax⁡−1)\rho(\eta) = \max_i\lvert 1 - \eta\lambda_i\rvert = \max\big(1 - \eta\lambda_{\min},\ \eta\lambda_{\max} - 1\big).For 0<η<2/λmax⁡0 < \eta < 2/\lambda_{\max} the values 1−ηλi1 - \eta\lambda_i lie between 1−ηλmax⁡1 - \eta\lambda_{\max} and 1−ηλmin⁡1 - \eta\lambda_{\min}, and the largest modulus is at one of the two ends.
  5. ρ\rho is minimised where the two branches are equal: 1−ηλmin⁡=ηλmax⁡−11 - \eta\lambda_{\min} = \eta\lambda_{\max} - 1, so η∗=2λmin⁡+λmax⁡\eta^* = \dfrac{2}{\lambda_{\min} + \lambda_{\max}} and ρ(η∗)=1−2λmin⁡λmin⁡+λmax⁡=λmax⁡−λmin⁡λmax⁡+λmin⁡=κ−1κ+1\rho(\eta^*) = 1 - \dfrac{2\lambda_{\min}}{\lambda_{\min} + \lambda_{\max}} = \dfrac{\lambda_{\max} - \lambda_{\min}}{\lambda_{\max} + \lambda_{\min}} = \dfrac{\kappa - 1}{\kappa + 1}.One branch decreases in η\eta and the other increases, so the maximum of the two is smallest where they cross; divide numerator and denominator by λmin⁡\lambda_{\min}.
  6. A=diag⁡(1,10)A = \operatorname{diag}(1, 10): κ=10\kappa = 10, η∗=2/11\eta^* = 2/11, rate 9/11≈0.8189/11 \approx 0.818; with η=1/λmax⁡=0.1\eta = 1/\lambda_{\max} = 0.1 the factors are 0.90.9 and 00, rate 0.90.9; with η=0.3>2/10\eta = 0.3 > 2/10 the stiff component grows by ∣1−3∣=2\lvert 1 - 3\rvert = 2 per step.Step 5 with λmin⁡=1\lambda_{\min} = 1, λmax⁡=10\lambda_{\max} = 10; the other two step sizes from step 4.
  7. ek+1=(I−ηA)eke_{k+1} = (I - \eta A)e_k; convergence from every start   ⟺  0<η<2/λmax⁡\iff 0 < \eta < 2/\lambda_{\max}; the qiq_i component scales by ∣1−ηλi∣\lvert 1 - \eta\lambda_i\rvert; η∗=2λmin⁡+λmax⁡\eta^* = \dfrac2{\lambda_{\min} + \lambda_{\max}} with rate κ−1κ+1\dfrac{\kappa - 1}{\kappa + 1}; for diag⁡(1,10)\operatorname{diag}(1, 10): η∗=2/11\eta^* = 2/11, rate 9/119/11The step size is set by the stiffest direction and the speed by the flattest: at η∗\eta^* the error shrinks by (κ−1)/(κ+1)≈1−2/κ(\kappa - 1)/(\kappa + 1) \approx 1 - 2/\kappa per step, so reaching accuracy ϵ\epsilon takes about κ2log⁡(1/ϵ)\tfrac\kappa2\log(1/\epsilon) steps, linear in the condition number. For a general smooth ff the same analysis applies to the Hessian at the minimum, which is why conditioning is the quantity that normalisation, preconditioning and Adam's per-coordinate scaling attack, and why Newton's method, which multiplies by A−1A^{-1} and makes every λi\lambda_i effectively 11, converges in one step on a quadratic. Mistake 5 chooses η\eta from the wrong eigenvalue.

Problem 10

For any square matrix MM, not necessarily symmetric, show that x⊤Mx=x⊤Sxx^\top Mx = x^\top Sx with S=12(M+M⊤)S = \tfrac12(M + M^\top). Show that M=[1401]M = \begin{bmatrix}1&4\\0&1\end{bmatrix} has both eigenvalues equal to 11 and yet v⊤Mv<0v^\top Mv < 0 for some vv. Why does the eigenvalue test of Problem 2 not apply?

  1. x⊤Mx=(x⊤Mx)⊤=x⊤M⊤xx^\top Mx = (x^\top Mx)^\top = x^\top M^\top x.A 1×11\times1 matrix equals its transpose, and (x⊤Mx)⊤=x⊤M⊤x(x^\top Mx)^\top = x^\top M^\top x.
  2. x⊤Mx=12(x⊤Mx+x⊤M⊤x)=x⊤ 12(M+M⊤) x=x⊤Sxx^\top Mx = \tfrac12\big(x^\top Mx + x^\top M^\top x\big) = x^\top\,\tfrac12(M + M^\top)\,x = x^\top Sx.Average the two equal expressions and factor out x⊤x^\top and xx.
  3. MM is upper-triangular with diagonal (1,1)(1, 1), so its eigenvalues are 1,11, 1.The eigenvalues of a triangular matrix are its diagonal entries (the eigenvalues page's Problem 4).
  4. S=12([1401]+[1041])=[1221]S = \tfrac12\Big(\begin{bmatrix}1&4\\0&1\end{bmatrix} + \begin{bmatrix}1&0\\4&1\end{bmatrix}\Big) = \begin{bmatrix}1&2\\2&1\end{bmatrix}, Problem 1's BB, indefinite with eigenvalues 3,−13, -1.Add MM to its transpose and halve.
  5. v=(1,−1)⊤v = (1, -1)^\top: v⊤Mv=1⋅1+4⋅1⋅(−1)+0+1⋅1=−2v^\top Mv = 1\cdot 1 + 4\cdot 1\cdot(-1) + 0 + 1\cdot 1 = -2.Expand x⊤Mx=M11x12+M12x1x2+M21x2x1+M22x22x^\top Mx = M_{11}x_1^2 + M_{12}x_1x_2 + M_{21}x_2x_1 + M_{22}x_2^2 with x=(1,−1)⊤x = (1, -1)^\top; it agrees with v⊤Sv=−2v^\top Sv = -2 from Problem 1.
  6. x⊤Mx=x⊤12(M+M⊤)xx^\top Mx = x^\top\tfrac12(M + M^\top)x; M=[1401]M = \begin{bmatrix}1&4\\0&1\end{bmatrix} has eigenvalues 1,11, 1 but (1,−1)M(1,−1)⊤=−2(1, -1)M(1, -1)^\top = -2; the eigenvalue test needs a symmetric matrixA quadratic form sees only the symmetric part of its matrix; the antisymmetric part 12(M−M⊤)\tfrac12(M - M^\top) contributes x⊤Kx=0x^\top Kx = 0 because x⊤Kx=−x⊤K⊤x=−x⊤Kxx^\top Kx = -x^\top K^\top x = -x^\top Kx. Problem 2 used M=QΛQ⊤M = Q\Lambda Q^\top with orthonormal QQ, which non-symmetric matrices do not have: MM here has a single eigenvector direction (it is a shear) and no orthogonal eigenbasis, so its eigenvalues say nothing about its quadratic form (Mistake 2). This is also why the matrix-calculus page's ∇(x⊤Mx)=(M+M⊤)x\nabla(x^\top Mx) = (M + M^\top)x has the symmetrised matrix in it, and why the Hessians page symmetrises AA before reading off definiteness.

Where this goes wrong

1. Reading positive definite off a positive determinant

Sylvester's criterion is remembered as “the determinant is positive”, which is the last of its conditions and not the first.

  1. [abbc]≻0  ⟺  a>0\begin{bmatrix}a&b\\b&c\end{bmatrix} \succ 0 \iff a > 0 and ac−b2>0ac - b^2 > 0Right so far: Problem 3.
  2. “The determinant is what decides it: positive determinant, positive definite.”The shortcut that causes the mistake: Problem 3's proof needed the leading entry a>0a > 0 first, and the determinant only afterwards.
  3. A=[−100−1]A = \begin{bmatrix}-1&0\\0&-1\end{bmatrix} has det⁡A=1>0\det A = 1 > 0, so A≻0A \succ 0x⊤Ax=−∥x∥2<0x^\top Ax = -\|x\|^2 < 0 for every x≠0x \neq 0: negative definite. The determinant is the product of the eigenvalues, and two negative eigenvalues multiply to a positive number; diag⁡(4,−1,−1)\operatorname{diag}(4, -1, -1) does the same in three dimensions with a positive trace too. The criterion needs every leading principal minor positive, aa and then ac−b2ac - b^2, which for diag⁡(−1,−1)\operatorname{diag}(-1, -1) fails at the first. The cheapest decisive test is Problem 5's: attempt the Cholesky factorisation and watch for a non-positive pivot, which here fails at −1\sqrt{-1}.

2. Trusting the eigenvalues of a non-symmetric matrix

Positive eigenvalues mean positive definite, and the matrix at hand is not checked for symmetry before the test is applied.

  1. A=QΛQ⊤≻0  ⟺  A = Q\Lambda Q^\top \succ 0 \iff every λi>0\lambda_i > 0Right so far: Problem 2, for symmetric AA.
  2. “Eigenvalues are eigenvalues; compute them and look at the signs.”The habit that causes the mistake: Problem 2's proof wrote x⊤Ax=∑iλi(qi⊤x)2x^\top Ax = \sum_i\lambda_i(q_i^\top x)^2, which needs an orthonormal eigenbasis, and only symmetric matrices are guaranteed one.
  3. M=[1401]M = \begin{bmatrix}1&4\\0&1\end{bmatrix} has eigenvalues 1,1>01, 1 > 0, so x⊤Mx>0x^\top Mx > 0 for all x≠0x \neq 0(1,−1)M(1,−1)⊤=−2(1, -1)M(1, -1)^\top = -2 (Problem 10). The quadratic form of MM is the quadratic form of 12(M+M⊤)=[1221]\tfrac12(M + M^\top) = \begin{bmatrix}1&2\\2&1\end{bmatrix}, whose eigenvalues are 33 and −1-1, so the form is indefinite. The right procedure for a non-symmetric matrix is to symmetrise first and then test; a Jacobian ∂f/∂x\partial f/\partial x of a non-gradient vector field is the usual place this comes up, and the Hessians page's 12(A+A⊤)\tfrac12(A + A^\top) is the same step taken for the Hessian of 12x⊤Ax\tfrac12x^\top Ax.

3. Sampling with the transposed Cholesky factor

A=LL⊤A = LL^\top and A=L⊤LA = L^\top L look alike, and whichever factor is to hand gets multiplied onto the noise.

  1. A=LL⊤A = LL^\top with L=[200120112]L = \begin{bmatrix}2&0&0\\1&2&0\\1&1&2\end{bmatrix}, and x=μ+Lεx = \mu + L\varepsilon has covariance LL⊤=ALL^\top = A for ε∼N(0,I)\varepsilon \sim \mathcal{N}(0, I)Right so far: Problem 5 and the Gaussian page's Problem 7.
  2. “LL and L⊤L^\top are the same factor, just written the other way.”The habit that causes the mistake: the covariance of MεM\varepsilon is MM⊤MM^\top, and the order of the two factors is not optional.
  3. x=μ+L⊤εx = \mu + L^\top\varepsilon has covariance AAIts covariance is L⊤(L⊤)⊤=L⊤L=[632352224]≠AL^\top(L^\top)^\top = L^\top L = \begin{bmatrix}6&3&2\\3&5&2\\2&2&4\end{bmatrix} \neq A: the first coordinate now has variance 66 instead of 44. L⊤LL^\top L and LL⊤LL^\top share eigenvalues and determinant (6464 in both cases), so a check on those would not catch it; a check on Var⁡(x1)\operatorname{Var}(x_1) would. The same slip in the other direction happens in the whitening step, L−1(x−μ)L^{-1}(x - \mu) against L−⊤(x−μ)L^{-\top}(x - \mu), and in software it is the difference between a library returning the lower factor and one returning the upper. Problem 8's symmetric root A1/2A^{1/2} has no such ambiguity, which is one reason to prefer it when cost is not the issue.

4. Assuming the normal equations have a unique solution

X⊤XX^\top X is positive semidefinite and usually positive definite, and the usual case becomes the only case.

  1. X⊤X⪰0X^\top X \succeq 0 for every XX, with v⊤X⊤Xv=∥Xv∥2v^\top X^\top Xv = \|Xv\|^2Right so far: Problem 4, step 1.
  2. “A Gram matrix is positive definite, so (X⊤X)−1(X^\top X)^{-1} exists and w=(X⊤X)−1X⊤yw = (X^\top X)^{-1}X^\top y.”The habit that causes the mistake: Problem 4 made PD conditional on linearly independent columns, and nothing has been said about the columns.
  3. w∗=(X⊤X)−1X⊤yw^* = (X^\top X)^{-1}X^\top y is the unique least-squares solution for any XXIf two features are collinear, or there are more features than examples (d>Nd > N), some v≠0v \neq 0 has Xv=0Xv = 0, X⊤XX^\top X has a zero eigenvalue and is singular, and every w∗+tvw^* + tv fits equally well: a whole line (or more) of minimisers, as in Problem 6's PSD case. Problem 1's C=[1224]C = \begin{bmatrix}1&2\\2&4\end{bmatrix} is X⊤XX^\top X for the single row X=(1,2)X = (1, 2), and its null vector (2,−1)⊤(2, -1)^\top is the direction along which the fit cannot tell the features apart. Ridge adds λI\lambda I and restores a unique solution (Problem 4), and the least-squares page's pseudoinverse picks the minimiser of smallest norm; both are choices, not consequences of the normal equations.

5. Choosing the gradient-descent step from the smallest eigenvalue

The slow direction is the one with the small eigenvalue, and the step is enlarged to speed it up.

  1. The component of the error along qiq_i scales by 1−ηλi1 - \eta\lambda_i per stepRight so far: Problem 9, step 2.
  2. “The slowest direction is λmin⁡\lambda_{\min}, so pick η\eta to make 1−ηλmin⁡1 - \eta\lambda_{\min} small.”The habit that causes the mistake: Problem 9's convergence condition is on λmax⁡\lambda_{\max}; the step that is right for the flattest direction is far too long for the stiffest.
  3. For A=diag⁡(1,10)A = \operatorname{diag}(1, 10), take η=1=1/λmin⁡\eta = 1 = 1/\lambda_{\min}, which kills the slow component in one stepThe stiff component scales by 1−10=−91 - 10 = -9: after kk steps it is (−9)k(-9)^k times its start, so the iteration diverges, oscillating across the valley in ever larger swings. Any η≥2/λmax⁡=0.2\eta \ge 2/\lambda_{\max} = 0.2 does this. The admissible range is 0<η<0.20 < \eta < 0.2, the best choice is η∗=2/11\eta^* = 2/11 (Problem 9), and the slow direction then shrinks by only 9/119/11 per step: with a single step size the slow direction cannot be sped up without breaking the fast one, and that gap, κ\kappa, is what momentum (the optimisers page) and preconditioning exist to close.

Print this set: positive-definite-matrices-and-quadratic-forms.pdf (problems, answers, and worked solutions on separate pages).