Type at least 2 letters. Enter opens the first result, Esc closes.

    Linear Algebra · Lesson 7 · Eigenvalues and the spectral theorem

    Positive (semi-)definite matrices, the five tests, Cholesky, Schur complements and the Loewner order

    Intermediate 90 min 4 interactive figures 3 videos Colab notebook

    Before this lesson: lesson 06 (you need S=QΛQ⊤S = Q\Lambda Q^\top) and lesson 03 (determinants). Time: about 90 minutes, plus the notebook.


    Why this matters #

    A positive definite matrix is the matrix version of a positive number. Covariance matrices, kernel (Gram) matrices, the Hessian at a strict minimum, the Fisher information and finite-element stiffness matrices all have this property. Three practical questions follow. Is my matrix PD? (Is the loss a bowl here? Is my covariance valid?) How do I compute with it cheaply? (Cholesky: solve, sample, log-determinant.) How do I compare two such matrices? (The Loewner order: "the posterior uncertainty is smaller than the prior uncertainty in every direction".) Gaussian processes and Kalman filters use all three every time they condition on data, and the formula they use is a Schur complement.

    1. Predict first #

    2. The picture #

    Start with one number ss. The function f(x)=sx2f(x) = s x^2 is a parabola that opens upward when s>0s > 0, is flat when s=0s = 0, and opens downward when s<0s < 0.

    Now take a 2×22 \times 2 diagonal matrix S=diag⁡(λ1,λ2)S = \operatorname{diag}(\lambda_1, \lambda_2). Its energy (also called the quadratic form) is x⊤Sx=λ1x12+λ2x22x^\top S x = \lambda_1 x_1^2 + \lambda_2 x_2^2.

    • λ1,λ2>0\lambda_1, \lambda_2 > 0: a bowl. The energy is positive in every direction.
    • λ1>0=λ2\lambda_1 > 0 = \lambda_2: a trough. The energy is zero along the x2x_2-axis.
    • λ1>0>λ2\lambda_1 > 0 > \lambda_2: a saddle. Up in one direction, down in another.

    A general symmetric SS is the same picture, rotated. The spectral theorem gives S=QΛQ⊤S = Q\Lambda Q^\top with QQ orthogonal (lesson 06). In the rotated coordinates y=Q⊤xy = Q^\top x:

    x⊤Sx=y⊤Λy=∑iλiyi2.x^\top S x = y^\top \Lambda y = \sum_i \lambda_i y_i^2 .

    So the signs of the eigenvalues decide everything. All positive: a bowl (PD). All non-negative: a bowl or a trough (PSD). Mixed signs: a saddle (indefinite). For a PD SS, the level set {x:x⊤Sx=1}\{x : x^\top S x = 1\} is an ellipse (an ellipsoid in nn dimensions) with axes along the eigenvectors qiq_i and semi-axis lengths 1/λi1/\sqrt{\lambda_i}.

    Interactive figure: loading…

    Change aa, bb, cc in S=(abbc)S = \begin{pmatrix} a & b \\ b & c \end{pmatrix} and drag to rotate. The surface is the energy x⊤Sxx^\top S x: aqua where it is positive, magenta where it is negative. The arrows on the floor are the eigenvectors q1q_1 and q2q_2. Go from bowl to trough to saddle and watch λ2\lambda_2 cross 0. Then try (1221)\begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix}: positive entries, but a saddle.

    Covariance. For a random vector xx with covariance Σ\Sigma and a fixed direction ww, Var⁡(w⊤x)=w⊤Σw\operatorname{Var}(w^\top x) = w^\top \Sigma w. A variance cannot be negative, so covariance matrices are PSD.

    Quick check

    A symmetric 2×22 \times 2 matrix has eigenvalues 33 and 00, with eigenvectors q1q_1 and q2q_2. What does its energy surface x⊤Sxx^\top S x look like?

    3. Definitions and main results #

    PD and PSD #

    A symmetric matrix S∈Rn×nS \in \mathbb{R}^{n \times n} is

    • positive definite (S≻0S \succ 0) if x⊤Sx>0x^\top S x > 0 for every x≠0x \ne 0;
    • positive semidefinite (S⪰0S \succeq 0) if x⊤Sx≥0x^\top S x \ge 0 for every xx.

    By the picture above, S≻0S \succ 0 exactly when all eigenvalues are >0> 0, and S⪰0S \succeq 0 exactly when all eigenvalues are ≥0\ge 0. We always assume SS is symmetric. For a non-symmetric MM, the energy only sees the symmetric part: x⊤Mx=x⊤12(M+M⊤) xx^\top M x = x^\top \tfrac{1}{2}(M + M^\top)\, x.

    Sample covariance is PSD. Let X∈RN×dX \in \mathbb{R}^{N \times d} hold NN samples as rows, let xˉ\bar x be the mean sample, and let XcX_c be the centered data (row jj is (xj−xˉ)⊤(x_j - \bar x)^\top). The sample covariance is S=Xc⊤Xc/(N−1)S = X_c^\top X_c / (N-1). For any w∈Rdw \in \mathbb{R}^d:

    w⊤Sw=∥Xcw∥2N−1=1N−1∑j=1N(w⊤(xj−xˉ))2≥0,w^\top S w = \frac{\|X_c w\|^2}{N-1} = \frac{1}{N-1} \sum_{j=1}^N \big(w^\top (x_j - \bar x)\big)^2 \ge 0 ,

    the sample variance of the data projected on ww. It is zero exactly when Xcw=0X_c w = 0: every centered sample is orthogonal to ww, so the data lie in a hyperplane (for example, two features that are exact copies). The rows of XcX_c sum to zero, so rank⁡S≤N−1\operatorname{rank} S \le N - 1. With d≥Nd \ge N features, SS is always singular.

    Theorem (the five tests) #

    For a symmetric S∈Rn×nS \in \mathbb{R}^{n\times n}, these five statements are equivalent:

    1. Eigenvalues: all λi>0\lambda_i > 0.
    2. Energy: x⊤Sx>0x^\top S x > 0 for every x≠0x \ne 0.
    3. Gram form: S=A⊤AS = A^\top A for some matrix AA with independent columns.
    4. Leading minors: Dk=det⁡S[1:k, 1:k]>0D_k = \det S_{[1:k,\,1:k]} > 0 for k=1,…,nk = 1, \dots, n (the top-left k×kk \times k blocks).
    5. Pivots: elimination without row exchanges gives nn pivots d1,…,dnd_1, \dots, d_n, all >0> 0.

    Proof of 1 ⇔ 2 ⇔ 3.

    1. (1 ⇒ 2) Write S=QΛQ⊤S = Q\Lambda Q^\top. For x≠0x \ne 0, y=Q⊤x≠0y = Q^\top x \ne 0 because QQ is invertible. Then x⊤Sx=∑iλiyi2>0x^\top S x = \sum_i \lambda_i y_i^2 > 0: every λi>0\lambda_i > 0 and some yi≠0y_i \ne 0.
    2. (2 ⇒ 1) Take a real unit eigenvector qq with Sq=λqSq = \lambda q (it exists because SS is symmetric). Then 0<q⊤Sq=λ q⊤q=λ0 < q^\top S q = \lambda\, q^\top q = \lambda.
    3. (3 ⇒ 2) x⊤A⊤Ax=∥Ax∥2≥0x^\top A^\top A x = \|Ax\|^2 \ge 0. It is 00 only if Ax=0Ax = 0, and independent columns force x=0x = 0.
    4. (1 ⇒ 3) Set A=Λ1/2Q⊤A = \Lambda^{1/2} Q^\top. It is square and invertible, so its columns are independent, and A⊤A=QΛ1/2Λ1/2Q⊤=SA^\top A = Q \Lambda^{1/2}\Lambda^{1/2} Q^\top = S.

    Why the determinant tests work, in one line. Elimination does not change the leading minors, and at the end Dk=d1d2⋯dkD_k = d_1 d_2 \cdots d_k. So the pivots are the ratios dk=Dk/Dk−1d_k = D_k / D_{k-1}, and "all Dk>0D_k > 0" is the same as "all dk>0d_k > 0". The proof below makes this precise and links tests 4 and 5 to the energy.

    Proof of 4 ⇔ 5, and how they join 1–3
    1. Elimination without row exchanges subtracts a multiple of row jj from a later row i>ji > j. If i≤ki \le k, this is a row operation inside the top-left k×kk\times k block, so the block's determinant does not change. If i>ki > k, the block does not change at all. So every DkD_k stays the same during elimination.
    2. At the end, the top-left k×kk \times k block of UU is upper triangular with diagonal d1,…,dkd_1, \dots, d_k. So Dk=d1d2⋯dkD_k = d_1 d_2 \cdots d_k, and dk=Dk/Dk−1d_k = D_k / D_{k-1} (with D0=1D_0 = 1).
    3. Hence all Dk>0D_k > 0 ⇔ all dk>0d_k > 0. (If all Dk>0D_k > 0, each pivot is a ratio of positive numbers, so elimination never meets a zero pivot.)
    4. (2 ⇒ 4) For xx whose entries after position kk are zero, x⊤Sx=x1:k⊤S[1:k,1:k] x1:kx^\top S x = x_{1:k}^\top S_{[1:k,1:k]}\, x_{1:k}. So each leading block is PD, its eigenvalues are positive, and DkD_k, their product, is positive.
    5. (5 ⇒ 2) With nonzero pivots, elimination gives S=L~US = \tilde L U with L~\tilde L unit lower triangular. Symmetry and the uniqueness of the LDU factorization give U=DL~⊤U = D\tilde L^\top with D=diag⁡(d1,…,dn)D = \operatorname{diag}(d_1, \dots, d_n), so S=L~DL~⊤S = \tilde L D \tilde L^\top. Then x⊤Sx=∑jdj((L~⊤x)j)2>0x^\top S x = \sum_j d_j \big((\tilde L^\top x)_j\big)^2 > 0 for x≠0x \ne 0, because L~⊤\tilde L^\top is invertible. ■\blacksquare

    The PSD trap: leading minors are not enough #

    Tests 1–3 carry over to PSD with ≥\ge: eigenvalues ≥0\ge 0, energy ≥0\ge 0, and S=A⊤AS = A^\top A for any AA (dependent columns give the zero eigenvalues). Test 4 does not carry over.

    PD (≻0\succ 0) PSD (⪰0\succeq 0)
    determinant test the nn leading minors are >0> 0 all 2n−12^n - 1 principal minors are ≥0\ge 0
    why the shortcut fails — a zero leading minor hides what comes after it
    counterexample — T=(000−1)T = \begin{pmatrix} 0 & 0 \\ 0 & -1 \end{pmatrix}: leading minors 0,00, 0, but e2⊤Te2=−1e_2^\top T e_2 = -1

    A principal minor is the determinant of the submatrix with the same set of row and column indices, for example rows and columns {2}\{2\} or {1,3}\{1, 3\}. The leading minors are only the index sets {1},{1,2},…\{1\}, \{1, 2\}, \dots.

    Why the shortcut fails, step by step. For PD, each Dk>0D_k > 0 and the pivot dk=Dk/Dk−1d_k = D_k/D_{k-1} is defined. When some Dk−1=0D_{k-1} = 0, this ratio does not exist: the leading minors stop giving information about the later pivots. In TT, D1=0D_1 = 0 already, so D2=0D_2 = 0 says nothing about the entry −1-1. The principal minor with index set {2}\{2\} sees it directly. The 3×33\times 3 version is the minors 0, 0, 0 preset in the figure: leading minors 0,0,00, 0, 0, but the principal minor M22=−1M_{22} = -1.

    Test 5 is stated for PD: a singular PSD matrix has a zero pivot, and plain elimination then stops (pivoted Cholesky handles this case).

    Interactive figure: loading…

    Edit an entry or pick a preset; all five tests run at once. For a PD matrix all five pass, and otherwise all five fail: they are one property seen five ways. Note how the pivots, the Cholesky radicands and the ratios Dk/Dk−1D_k/D_{k-1} are the same numbers. Try minors 0, 0, 0: the leading minors look harmless, but a principal minor is negative, so the matrix is not even PSD.

    Quick check

    M=(11011000−1)M = \begin{pmatrix} 1 & 1 & 0 \\ 1 & 1 & 0 \\ 0 & 0 & -1 \end{pmatrix} has leading minors D1=1D_1 = 1, D2=0D_2 = 0, D3=0D_3 = 0. Is MM positive semidefinite?

    Cholesky #

    Theorem. SS is PD if and only if S=LL⊤S = LL^\top with LL lower triangular with a positive diagonal. This LL is unique. It is the Cholesky factor of SS.

    By hand, 2×22\times 2. Take S=(4223)S = \begin{pmatrix} 4 & 2 \\ 2 & 3 \end{pmatrix} and write the unknown factor:

    LL⊤=(ℓ110ℓ21ℓ22)(ℓ11ℓ210ℓ22)=(ℓ112ℓ11ℓ21ℓ11ℓ21ℓ212+ℓ222).LL^\top = \begin{pmatrix} \ell_{11} & 0 \\ \ell_{21} & \ell_{22} \end{pmatrix} \begin{pmatrix} \ell_{11} & \ell_{21} \\ 0 & \ell_{22} \end{pmatrix} = \begin{pmatrix} \ell_{11}^2 & \ell_{11}\ell_{21} \\ \ell_{11}\ell_{21} & \ell_{21}^2 + \ell_{22}^2 \end{pmatrix} .

    Match the entries one at a time:

    1. Entry (1,1)(1,1): ℓ112=4\ell_{11}^2 = 4, so ℓ11=2\ell_{11} = 2.
    2. Entry (2,1)(2,1): ℓ11ℓ21=2\ell_{11}\ell_{21} = 2, so ℓ21=2/2=1\ell_{21} = 2/2 = 1.
    3. Entry (2,2)(2,2): ℓ212+ℓ222=3\ell_{21}^2 + \ell_{22}^2 = 3, so ℓ222=3−1=2\ell_{22}^2 = 3 - 1 = 2 and ℓ22=2\ell_{22} = \sqrt 2.

    So L=(2012)L = \begin{pmatrix} 2 & 0 \\ 1 & \sqrt2 \end{pmatrix}, and the energy is a sum of squares: x⊤Sx=∥L⊤x∥2=(2x1+x2)2+2x22x^\top S x = \|L^\top x\|^2 = (2x_1 + x_2)^2 + 2x_2^2.

    Where it breaks. Do the same for the predict matrix (1221)\begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix}: ℓ11=1\ell_{11} = 1, ℓ21=2\ell_{21} = 2, and step 3 needs ℓ222=1−22=−3\ell_{22}^2 = 1 - 2^2 = -3. No real number squares to −3-3, so the factorization stops. The number under the square root, −3-3, is the second pivot 1−2⋅2/11 - 2\cdot 2/1. The energy shows the same thing: x⊤Sx=(x1+2x2)2−3x22x^\top S x = (x_1 + 2x_2)^2 - 3x_2^2, which is −3-3 at x=(−2,1)x = (-2, 1).

    The general algorithm. The same matching works for any nn.

    1. For i≥ji \ge j, entry (i,j)(i, j) of LL⊤LL^\top is Sij=∑k=1jLikLjkS_{ij} = \sum_{k=1}^{j} L_{ik} L_{jk} (terms with k>jk > j vanish because Ljk=0L_{jk} = 0).
    2. Diagonal (i=ji = j): Ljj=Sjj−∑k<jLjk2L_{jj} = \sqrt{S_{jj} - \sum_{k<j} L_{jk}^2}.
    3. Below the diagonal (i>ji > j): Lij=(Sij−∑k<jLikLjk)/LjjL_{ij} = \big(S_{ij} - \sum_{k<j} L_{ik}L_{jk}\big) / L_{jj}.
    4. Go column by column, j=1,…,nj = 1, \dots, n. Each formula uses only entries of earlier columns and the current LjjL_{jj}.

    Where PD is needed. From S=L~DL~⊤S = \tilde L D \tilde L^\top (proof of the five tests), the matrix L~D1/2\tilde L D^{1/2} is lower triangular with diagonal dj\sqrt{d_j}, so by uniqueness it is LL. The number under the square root at step jj (the radicand) is exactly the jj-th pivot djd_j. If SS is not PD, some radicand is ≤0\le 0 and the algorithm stops. This is the standard practical PD test: np.linalg.cholesky raises LinAlgError.

    Uniqueness of the Cholesky factor

    Let LL⊤=MM⊤LL^\top = MM^\top with both diagonals positive. Then M−1L=M⊤L−⊤M^{-1}L = M^\top L^{-\top}. The left side is lower triangular and the right side is upper triangular, so both equal a diagonal matrix Δ\Delta with positive diagonal Lii/MiiL_{ii}/M_{ii}. Then L=MΔL = M\Delta, and MM⊤=MΔ2M⊤MM^\top = M\Delta^2M^\top gives Δ2=I\Delta^2 = I, so Δ=I\Delta = I. So for a PD matrix and a fixed order of the variables, the Cholesky factor with a positive diagonal is unique. Other factors appear only with negative diagonal entries or reordered variables. ■\blacksquare

    Cost and uses. About n3/3n^3/3 flops, half of LU's 2n3/32n^3/3. After that, Sx=bSx = b costs two triangular solves (Ly=bLy = b, then L⊤x=yL^\top x = y), and log⁡det⁡S=2∑jlog⁡Ljj\log\det S = 2\sum_j \log L_{jj}.

    Quick check

    What is ℓ22\ell_{22} in the Cholesky factor of S=(9335)S = \begin{pmatrix} 9 & 3 \\ 3 & 5 \end{pmatrix}?

    Sampling with the Cholesky factor #

    To draw x∼N(μ,S)x \sim \mathcal N(\mu, S): draw z∼N(0,I)z \sim \mathcal N(0, I) (independent standard normals) and set x=μ+Lzx = \mu + Lz. Why the covariance is SS, in two steps.

    1. E[Lz]=L E[z]=0\mathbb E[Lz] = L\,\mathbb E[z] = 0, so Cov⁡(Lz)=E[(Lz)(Lz)⊤]\operatorname{Cov}(Lz) = \mathbb E\big[(Lz)(Lz)^\top\big].
    2. (Lz)(Lz)⊤=L zz⊤L⊤(Lz)(Lz)^\top = L\,zz^\top L^\top, and the expectation is linear, so E[L zz⊤L⊤]=L E[zz⊤] L⊤=L I L⊤=S\mathbb E\big[L\,zz^\top L^\top\big] = L\,\mathbb E[zz^\top]\,L^\top = L\,I\,L^\top = S.

    A linear map of a Gaussian vector is Gaussian, and a Gaussian is fixed by its mean and covariance. So x=μ+Lzx = \mu + Lz has exactly the distribution N(μ,S)\mathcal N(\mu, S). Step 2 never used that LL is triangular: any MM with MM⊤=SMM^\top = S works, for example the symmetric square root S1/2=QΛ1/2Q⊤S^{1/2} = Q\Lambda^{1/2}Q^\top. Cholesky is the cheapest such MM. With NN samples stored as rows (ZZ is N×dN \times d): X=1μ⊤+ZL⊤X = \mathbf{1}\mu^\top + Z L^\top.

    Interactive figure: loading…

    Switch between white noise z, μ + Lz, μ + √S z and both, and follow the magenta point. The round cloud of white noise becomes the aqua ellipse of SS. With both, the blue cloud (LzLz) and the orange cloud (S1/2zS^{1/2}z) fill the same ellipse and have almost the same sample covariance, but the same zz lands in two different places. The violet arrows are the columns of the map; for LL the second one is vertical, because LL is lower triangular. Change ρ\rho and drag μ\mu.

    The Schur complement #

    The picture. Eliminate the first variable of S=(4223)S = \begin{pmatrix} 4 & 2 \\ 2 & 3 \end{pmatrix}: subtract 2/42/4 times row 1 from row 2. The entry that is left is 3−2⋅2/4=23 - 2\cdot 2/4 = 2. It is the second pivot, and it is ℓ222\ell_{22}^2 from the hand computation above. Do the same with whole blocks instead of single entries, and the number 3−2⋅2/43 - 2\cdot 2/4 becomes a matrix.

    Let M=(ABB⊤C)M = \begin{pmatrix} A & B \\ B^\top & C \end{pmatrix} be symmetric, with AA of size k×kk\times k and invertible. The Schur complement of AA in MM is

    M/A=C−B⊤A−1B.M/A = C - B^\top A^{-1} B .

    Block elimination subtracts B⊤A−1B^\top A^{-1} times the first block row from the second one: the second block row becomes (0C−B⊤A−1B)\begin{pmatrix} 0 & C - B^\top A^{-1}B \end{pmatrix}. So the pivots of MM are the pivots of AA followed by the pivots of M/AM/A, and det⁡M=det⁡A⋅det⁡(M/A)\det M = \det A \cdot \det(M/A).

    Theorem (Schur complement test). M≻0  ⟺  A≻0M \succ 0 \iff A \succ 0 and C−B⊤A−1B≻0C - B^\top A^{-1}B \succ 0.

    Proof.

    1. Let E=(IA−1B0I)E = \begin{pmatrix} I & A^{-1}B \\ 0 & I \end{pmatrix}. It is invertible (block triangular with identity blocks). Multiply out: E⊤(A00M/A)E=(ABB⊤B⊤A−1B+M/A)=ME^\top \begin{pmatrix} A & 0 \\ 0 & M/A \end{pmatrix} E = \begin{pmatrix} A & B \\ B^\top & B^\top A^{-1}B + M/A \end{pmatrix} = M.
    2. So for any xx, with y=Exy = Ex: x⊤Mx=y⊤(A00M/A)yx^\top M x = y^\top \begin{pmatrix} A & 0 \\ 0 & M/A \end{pmatrix} y. Because EE is invertible, x≠0  ⟺  y≠0x \ne 0 \iff y \ne 0.
    3. Hence M≻0M \succ 0 exactly when the block-diagonal matrix is PD, that is, when A≻0A \succ 0 and M/A≻0M/A \succ 0. (If M≻0M \succ 0, then A≻0A \succ 0 as a leading block, so A−1A^{-1} exists.) ■\blacksquare

    With A≻0A \succ 0, the same argument gives M⪰0  ⟺  M/A⪰0M \succeq 0 \iff M/A \succeq 0.

    Gaussian conditioning (the ML use). Split a Gaussian vector into two parts, x=(xa,xb)∼N(μ,Σ)x = (x_a, x_b) \sim \mathcal N(\mu, \Sigma) with Σ=(ΣaaΣabΣbaΣbb)\Sigma = \begin{pmatrix} \Sigma_{aa} & \Sigma_{ab} \\ \Sigma_{ba} & \Sigma_{bb} \end{pmatrix}. After you observe xax_a,

    xb∣xa∼N(μb+ΣbaΣaa−1(xa−μa),  Σbb−ΣbaΣaa−1Σab).x_b \mid x_a \sim \mathcal N\big(\mu_b + \Sigma_{ba}\Sigma_{aa}^{-1}(x_a - \mu_a),\ \ \Sigma_{bb} - \Sigma_{ba}\Sigma_{aa}^{-1}\Sigma_{ab}\big).

    The conditional covariance is the Schur complement Σ/Σaa\Sigma/\Sigma_{aa}. It is PSD (by the test), and it is ⪯Σbb\preceq \Sigma_{bb}, because the subtracted term ΣbaΣaa−1Σab\Sigma_{ba}\Sigma_{aa}^{-1}\Sigma_{ab} is PSD: observing xax_a never increases the uncertainty about xbx_b in any direction.

    Small check with Cholesky. Let Σ=(4223)\Sigma = \begin{pmatrix} 4 & 2 \\ 2 & 3 \end{pmatrix} and μ=0\mu = 0. With LL from above, x1=2z1x_1 = 2z_1 and x2=z1+2 z2x_2 = z_1 + \sqrt2\, z_2. Observing x1x_1 fixes z1=x1/2z_1 = x_1/2. What is left is x2=x1/2+2 z2x_2 = x_1/2 + \sqrt2\, z_2: mean x1/2=Σ21Σ11−1x1x_1/2 = \Sigma_{21}\Sigma_{11}^{-1}x_1 and variance 2=3−2⋅2/42 = 3 - 2\cdot 2/4, the Schur complement. A Gaussian-process posterior is this formula with Σaa=K+σ2I\Sigma_{aa} = K + \sigma^2 I (training points) and xbx_b = function values at test points.

    Quick check

    (x1,x2)(x_1, x_2) is Gaussian with covariance Σ=(2112)\Sigma = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}. What is Var⁡(x2∣x1)\operatorname{Var}(x_2 \mid x_1)?

    The Loewner order #

    For symmetric A,BA, B: A⪯BA \preceq B means B−A⪰0B - A \succeq 0, that is, x⊤Ax≤x⊤Bxx^\top A x \le x^\top B x for every xx. This is the Loewner order. The PSD matrices form a convex cone: sums and non-negative multiples of PSD matrices are PSD. The cone is not a subspace: if S≠0S \ne 0 is PSD, then −S-S is not.

    Theorem. ⪯\preceq is a partial order on symmetric matrices (reflexive, antisymmetric, transitive), and it is not a total order: some pairs cannot be compared. Example: A=diag⁡(2,1)A = \operatorname{diag}(2, 1) and B=diag⁡(1,2)B = \operatorname{diag}(1, 2). B−A=diag⁡(−1,1)B - A = \operatorname{diag}(-1, 1) is indefinite, so neither A⪯BA \preceq B nor B⪯AB \preceq A.

    Proof that ⪯\preceq is a partial order
    1. Reflexive: A−A=0⪰0A - A = 0 \succeq 0.
    2. Antisymmetric: let B−A⪰0B - A \succeq 0 and A−B⪰0A - B \succeq 0. The symmetric matrix D=B−AD = B - A has all eigenvalues ≥0\ge 0 and ≤0\le 0, so all are 00, and D=Q 0 Q⊤=0D = Q\,0\,Q^\top = 0. (Symmetry matters here: a 90°90° rotation RR has x⊤Rx=0x^\top R x = 0 for all xx but R≠0R \ne 0.)
    3. Transitive: C−A=(C−B)+(B−A)C - A = (C - B) + (B - A) is a sum of PSD matrices, so it is PSD.
    4. Not total: the pair diag⁡(2,1)\operatorname{diag}(2, 1), diag⁡(1,2)\operatorname{diag}(1, 2) above. ■\blacksquare

    Useful facts. If A⪯BA \preceq B, then C⊤AC⪯C⊤BCC^\top A C \preceq C^\top B C for any matrix CC (apply the energy to CxCx), and λk(A)≤λk(B)\lambda_k(A) \le \lambda_k(B) for every kk (Courant–Fischer, lesson 06). For PD matrices, A⪯BA \preceq B implies B−1⪯A−1B^{-1} \preceq A^{-1}. Geometrically, for PD A⪯BA \preceq B the ellipsoid {x:x⊤Bx≤1}\{x : x^\top B x \le 1\} lies inside {x:x⊤Ax≤1}\{x : x^\top A x \le 1\}. Ridge is the simplest example: S⪯S+λIS \preceq S + \lambda I for every λ≥0\lambda \ge 0.

    The covariance picture. For a covariance it is more natural to draw EM={x:x⊤M−1x≤1}={M1/2z:∥z∥≤1}\mathcal E_M = \{x : x^\top M^{-1} x \le 1\} = \{M^{1/2}z : \|z\| \le 1\}, with half-axes λi\sqrt{\lambda_i} along the eigenvectors. Its width in a unit direction uu is max⁡∥z∥≤1u⊤M1/2z=∥M1/2u∥=u⊤Mu\max_{\|z\| \le 1} u^\top M^{1/2} z = \|M^{1/2}u\| = \sqrt{u^\top M u}, the standard deviation along uu. So A⪯BA \preceq B says: in every direction, EA\mathcal E_A is at most as wide as EB\mathcal E_B, that is, EA⊆EB\mathcal E_A \subseteq \mathcal E_B.

    Interactive figure: loading…

    Compare two ellipses EA\mathcal E_A (blue) and EB\mathcal E_B (orange). Turn the grey handle uu: the dashed lines touch each ellipse at its width u⊤Mu\sqrt{u^\top M u} in that direction. For diag⁡(2,1)\operatorname{diag}(2, 1) and diag⁡(1,2)\operatorname{diag}(1, 2), each is wider somewhere, so they are incomparable. Switch to S vs S + 0.8I (ridge) or posterior vs prior (a Kalman update): one ellipse sits inside the other, A⪯BA \preceq B. Drag the half-axis handles to make your own pair.

    The generalized eigenproblem Sx=λBxSx = \lambda Bx

    Linear discriminant analysis (LDA) maximizes w⊤SBw/w⊤SWww^\top S_B w / w^\top S_W w (between-class over within-class scatter), and canonical correlation analysis (CCA) has the same form. The critical points solve Sx=λBxSx = \lambda Bx with SS symmetric and B≻0B \succ 0. Cholesky reduces this to a symmetric problem of lesson 06:

    1. Factor B=LL⊤B = LL^\top and put y=L⊤xy = L^\top x, so x=L−⊤yx = L^{-\top}y.
    2. Then Sx=λLL⊤xSx = \lambda LL^\top x becomes L−1SL−⊤y=λyL^{-1}SL^{-\top}y = \lambda y.
    3. C=L−1SL−⊤C = L^{-1}SL^{-\top} is symmetric, so the λi\lambda_i are real and the yiy_i can be chosen orthonormal. The xi=L−⊤yix_i = L^{-\top}y_i are then BB-orthonormal: xi⊤Bxj=δijx_i^\top B x_j = \delta_{ij}.

    Example: S=(2113)S = \begin{pmatrix} 2 & 1 \\ 1 & 3 \end{pmatrix}, B=(4223)B = \begin{pmatrix} 4 & 2 \\ 2 & 3 \end{pmatrix} gives λ=0.5\lambda = 0.5 and 1.251.25. In SciPy: scipy.linalg.eigh(S, B).

    Answers to section 1. (1) No. The eigenvalues are 33 and −1-1, and x=(1,−1)x = (1, -1) gives x⊤Sx=−2x^\top S x = -2. Cholesky stops with radicand −3-3. (2) No. e2⊤Te2=−1<0e_2^\top T e_2 = -1 < 0. The leading-minor test works only for PD, with strict inequalities.

    4. Worked example #

    S=(422253236)S = \begin{pmatrix} 4 & 2 & 2 \\ 2 & 5 & 3 \\ 2 & 3 & 6 \end{pmatrix}

    Cholesky, column by column.

    • Column 1: L11=4=2L_{11} = \sqrt 4 = 2, L21=2/2=1L_{21} = 2/2 = 1, L31=2/2=1L_{31} = 2/2 = 1.
    • Column 2: L22=5−12=2L_{22} = \sqrt{5 - 1^2} = 2, L32=(3−1⋅1)/2=1L_{32} = (3 - 1\cdot 1)/2 = 1.
    • Column 3: L33=6−12−12=2L_{33} = \sqrt{6 - 1^2 - 1^2} = 2.
    L=(200120112),LL⊤=S ✓L = \begin{pmatrix} 2 & 0 & 0 \\ 1 & 2 & 0 \\ 1 & 1 & 2 \end{pmatrix}, \qquad LL^\top = S \ ✓

    The five tests agree.

    • Pivots = radicands: 4,4,44, 4, 4, all >0> 0.
    • Leading minors: D1=4D_1 = 4, D2=4⋅5−2⋅2=16D_2 = 4\cdot 5 - 2\cdot 2 = 16, D3=det⁡S=(det⁡L)2=82=64D_3 = \det S = (\det L)^2 = 8^2 = 64. The ratios 4/1, 16/4, 64/164/1,\ 16/4,\ 64/16 give the pivots back.
    • Energy as a sum of squares, from x⊤Sx=∥L⊤x∥2x^\top S x = \|L^\top x\|^2: x⊤Sx=(2x1+x2+x3)2+(2x2+x3)2+(2x3)2x^\top S x = (2x_1 + x_2 + x_3)^2 + (2x_2 + x_3)^2 + (2x_3)^2, which is >0> 0 unless x=0x = 0.
    • Gram form: A=L⊤A = L^\top is triangular with a nonzero diagonal, so its columns are independent.
    • Eigenvalues (numerically): 2.32, 2.79, 9.892.32,\ 2.79,\ 9.89. Check: sum =15=tr⁡S= 15 = \operatorname{tr} S, product =64=det⁡S= 64 = \det S.

    Schur complement. Split after the first row and column: A=(4)A = (4), B=(2,2)B = (2, 2), C=(5336)C = \begin{pmatrix} 5 & 3 \\ 3 & 6 \end{pmatrix}. Then

    M/A=C−B⊤A−1B=(5336)−14(4444)=(4225).M/A = C - B^\top A^{-1} B = \begin{pmatrix} 5 & 3 \\ 3 & 6 \end{pmatrix} - \frac14\begin{pmatrix} 4 & 4 \\ 4 & 4 \end{pmatrix} = \begin{pmatrix} 4 & 2 \\ 2 & 5 \end{pmatrix}.

    Its leading minors are 44 and 1616, so it is PD, and 4>04 > 0: by the Schur test, SS is PD. Its Cholesky factor is (2012)\begin{pmatrix} 2 & 0 \\ 1 & 2 \end{pmatrix}, the bottom-right block of LL.

    Sampling. x=Lzx = Lz reads x1=2z1x_1 = 2z_1, x2=z1+2z2x_2 = z_1 + 2z_2, x3=z1+z2+2z3x_3 = z_1 + z_2 + 2z_3. Two entries by hand: Var⁡(x2)=1+4=5\operatorname{Var}(x_2) = 1 + 4 = 5 and Cov⁡(x1,x2)=2⋅1=2\operatorname{Cov}(x_1, x_2) = 2 \cdot 1 = 2. ✓

    A failure. Change S33S_{33} from 66 to 11. Columns 1 and 2 of LL do not change, and the last radicand is 1−1−1=−11 - 1 - 1 = -1. Cholesky stops: the matrix is not PD. Indeed D3=4⋅4⋅(−1)=−16<0D_3 = 4 \cdot 4 \cdot (-1) = -16 < 0. (Preset S₃₃ = 1 in the five-tests figure.)

    Loewner. λmin⁡I⪯S⪯λmax⁡I\lambda_{\min} I \preceq S \preceq \lambda_{\max} I, here 2.32 I⪯S⪯9.89 I2.32\, I \preceq S \preceq 9.89\, I. But SS and its diagonal DS=diag⁡(4,5,6)D_S = \operatorname{diag}(4, 5, 6) are incomparable: DS−S≠0D_S - S \ne 0 has trace 00, so it has a positive and a negative eigenvalue (here −4.70, 1.70, 3-4.70,\ 1.70,\ 3).

    Quick check

    You store NN white-noise samples as the rows of ZZ (N×3N \times 3) and LL is the Cholesky factor of the SS above. Which data matrix has sample covariance close to SS?

    5. In code #

    NumPy checks the hand computations above. The notebook for this lesson has these cells and the exercises.

    import numpy as np
    
    S = np.array([[4., 2., 2.],
                  [2., 5., 3.],
                  [2., 3., 6.]])
    L = np.linalg.cholesky(S)                  # lower triangular, positive diagonal
    print(L)                                   # [[2,0,0],[1,2,0],[1,1,2]]
    print(np.diag(L) ** 2)                     # the pivots: [4. 4. 4.]
    print(np.array([np.linalg.det(S[:k, :k]) for k in (1, 2, 3)]).round(6))  # [ 4. 16. 64.]
    print(np.linalg.eigvalsh(S).round(2))      # [2.32 2.79 9.89]
    
    S_bad = S.copy()
    S_bad[2, 2] = 1.0
    try:
        np.linalg.cholesky(S_bad)
    except np.linalg.LinAlgError as err:
        print("not PD:", err)                  # not PD: Matrix is not positive definite
    
    T = np.array([[0., 0.], [0., -1.]])        # leading minors 0 and 0
    print(np.linalg.eigvalsh(T))               # [-1.  0.]: not PSD
    
    A, B, C = S[:1, :1], S[:1, 1:], S[1:, 1:]  # Schur complement of the 1x1 block
    schur = C - B.T @ np.linalg.solve(A, B)
    print(schur)                               # [[4. 2.] [2. 5.]]
    print(np.linalg.cholesky(schur))           # [[2. 0.] [1. 2.]] = L[1:, 1:]
    
    D_S = np.diag(np.diag(S))
    print(np.linalg.eigvalsh(D_S - S).round(2))   # [-4.7  1.7  3. ]: incomparable
    
    rng = np.random.default_rng(0)
    X = rng.multivariate_normal(np.zeros(3), S, size=200_000, method="cholesky")
    print(np.cov(X, rowvar=False).round(1))    # close to S
    

    6. Where it shows up #

    • Kernel and Gram matrices are PSD. If Kij=φ(xi)⊤φ(xj)K_{ij} = \varphi(x_i)^\top \varphi(x_j) for a feature map φ\varphi, then K=ΦΦ⊤K = \Phi\Phi^\top with rows φ(xi)⊤\varphi(x_i)^\top, and c⊤Kc=∥Φ⊤c∥2≥0c^\top K c = \|\Phi^\top c\|^2 \ge 0. A function k(x,x′)k(x, x') is a valid kernel exactly when every matrix [k(xi,xj)][k(x_i, x_j)] is PSD; this is the condition of Mercer's theorem. Kernel ridge regression, SVMs and Gaussian processes rely on it.
    • Gaussian processes. GP regression factors K+σ2I=LL⊤K + \sigma^2 I = LL^\top once, solves with two triangular solves, and gets log⁡det⁡\log\det from diag⁡(L)\operatorname{diag}(L). The posterior covariance at test points is a Schur complement. When Cholesky fails, add jitter such as 10−6I10^{-6} I.
    • Optimization. A PD Hessian at a stationary point means a strict local minimum. Newton solvers try a Cholesky of the (shifted) Hessian. The Gauss–Newton matrix J⊤JJ^\top J is PSD by the Gram test.
    • Data assimilation (ML for science). The error covariances BB and RR in 3D-Var or a Kalman filter must be PD. The Kalman posterior covariance Pa=Pf−PfH⊤(HPfH⊤+R)−1HPf⪯PfP_a = P_f - P_f H^\top (H P_f H^\top + R)^{-1} H P_f \preceq P_f is the Schur complement of the joint covariance of state and observation: data never increase the uncertainty in any direction. Correlated ensemble perturbations are drawn as μ+Lz\mu + Lz.
    • Statistics. The Cramér–Rao bound is a Loewner inequality: an unbiased estimator has Cov⁡(θ^)⪰I(θ)−1\operatorname{Cov}(\hat\theta) \succeq I(\theta)^{-1}, with I(θ)I(\theta) the Fisher information.
    • Simulation. Finite-element stiffness matrices (with boundary conditions) are symmetric PD, solved by Cholesky or conjugate gradients (lesson 14).

    7. Common mistakes #

    • "Positive entries mean PD." (1221)\begin{pmatrix}1&2\\2&1\end{pmatrix} is indefinite; (2−1−12)\begin{pmatrix}2&-1\\-1&2\end{pmatrix} is PD.
    • "det⁡S>0\det S > 0 means PD." diag⁡(−1,−1)\operatorname{diag}(-1, -1) has determinant 11.
    • Leading minors ≥0\ge 0 as a PSD test. Wrong (see TT). Use all principal minors, or eigenvalues ≥−tol\ge -\text{tol}.
    • Forgetting symmetry. M=(1301)M = \begin{pmatrix}1&3\\0&1\end{pmatrix} has eigenvalues 1,11, 1, but x=(1,−1)x = (1,-1) gives x⊤Mx=−1x^\top M x = -1. Test the symmetric part 12(M+M⊤)\tfrac12(M + M^\top).
    • Trusting random energy checks. They can find a negative direction but never prove PD: a singular PSD matrix passes.
    • Sampling with the wrong factor. x=L⊤zx = L^\top z has covariance L⊤L≠SL^\top L \ne S (in the worked example, L⊤LL^\top L has first row (6,3,2)(6, 3, 2)). With samples as rows, use ZL⊤Z L^\top, not ZLZ L.
    • Checking only the Schur complement. The test needs both A≻0A \succ 0 and M/A≻0M/A \succ 0. For M=(−1110)M = \begin{pmatrix} -1 & 1 \\ 1 & 0 \end{pmatrix} with A=(−1)A = (-1), the Schur complement is 0−1⋅1/(−1)=1>00 - 1\cdot 1/(-1) = 1 > 0, but MM is indefinite (det⁡M=−1\det M = -1), because A<0A < 0.
    • "A⪯BA \preceq B implies A2⪯B2A^2 \preceq B^2." False. A=diag⁡(2,0)A = \operatorname{diag}(2, 0) and B=(3111)B = \begin{pmatrix}3&1\\1&1\end{pmatrix}: B−A=(1111)⪰0B - A = \begin{pmatrix}1&1\\1&1\end{pmatrix} \succeq 0, but B2−A2=(6442)B^2 - A^2 = \begin{pmatrix}6&4\\4&2\end{pmatrix} has determinant −4<0-4 < 0. (The square root does keep the order.)

    8. Check yourself #

    1. Is (1225)\begin{pmatrix}1&2\\2&5\end{pmatrix} PD? Give its Cholesky factor and its energy as a sum of squares.
      AnswerYes: D1=1D_1 = 1 and D2=5−4=1D_2 = 5 - 4 = 1. L=(1021)L = \begin{pmatrix}1&0\\2&1\end{pmatrix}, so x⊤Sx=(x1+2x2)2+x22x^\top S x = (x_1 + 2x_2)^2 + x_2^2.
    2. For which aa is (1aa1)\begin{pmatrix}1&a\\a&1\end{pmatrix} PD? PSD?
      AnswerThe eigenvalues are 1±a1 \pm a. PD for ∣a∣<1|a| < 1, PSD for ∣a∣≤1|a| \le 1. (It is the correlation matrix of two variables with correlation aa.)
    3. Show that S≻0S \succ 0 implies S−1≻0S^{-1} \succ 0.
      AnswerS−1S^{-1} is symmetric with eigenvalues 1/λi>01/\lambda_i > 0. Or: for x≠0x \ne 0 put y=S−1x≠0y = S^{-1}x \ne 0; then x⊤S−1x=y⊤Sy>0x^\top S^{-1} x = y^\top S y > 0.
    4. You have N=5N = 5 samples of d=10d = 10 features. Can the sample covariance be PD?
      AnswerNo. rank⁡S≤N−1=4<10\operatorname{rank} S \le N - 1 = 4 < 10, so SS has at least 6 zero eigenvalues. Regularize (S+λIS + \lambda I, shrinkage) before you invert it.
    5. For which cc is M=(11012101c)M = \begin{pmatrix}1&1&0\\1&2&1\\0&1&c\end{pmatrix} PD? Use the Schur complement of the top-left 2×22\times 2 block.
      AnswerA=(1112)A = \begin{pmatrix}1&1\\1&2\end{pmatrix} is PD (D1=1D_1 = 1, D2=1D_2 = 1) and A−1=(2−1−11)A^{-1} = \begin{pmatrix}2&-1\\-1&1\end{pmatrix}. With B=(0,1)⊤B = (0, 1)^\top: B⊤A−1B=1B^\top A^{-1} B = 1, so M/A=c−1M/A = c - 1. MM is PD exactly when c>1c > 1. (Check: det⁡M=c−1\det M = c - 1.)
    6. If A⪯BA \preceq B, must λmax⁡(A)≤λmax⁡(B)\lambda_{\max}(A) \le \lambda_{\max}(B)? Is the converse true?
      AnswerYes: λmax⁡(A)=max⁡∥x∥=1x⊤Ax≤max⁡∥x∥=1x⊤Bx=λmax⁡(B)\lambda_{\max}(A) = \max_{\|x\|=1} x^\top A x \le \max_{\|x\|=1} x^\top B x = \lambda_{\max}(B). The converse is false: diag⁡(2,1)\operatorname{diag}(2,1) and diag⁡(1,2)\operatorname{diag}(1,2) have the same eigenvalues but are incomparable.
    Recall cardsAnswer in your head first, then reveal. Add the cards to your review deck to see them again just before you would forget.
    1. Define a positive definite matrix.

    2. Name the three PD tests that use eigenvalues, the energy, or a factor AA.

    3. Name the two PD tests that use determinants or elimination, and how they are linked.

    4. Why can leading minors ≥0\ge 0 not prove that a matrix is PSD?

    5. Compute the Cholesky factor of (4223)\begin{pmatrix} 4 & 2 \\ 2 & 3 \end{pmatrix}.

    6. When does a Cholesky factorization S=LL⊤S = LL^\top (positive diagonal) exist, and is it unique?

    7. Why does x=μ+Lzx = \mu + Lz with z∼N(0,I)z \sim \mathcal N(0, I) have covariance LL⊤LL^\top?

    8. Why is every Gram matrix K=ΦΦ⊤K = \Phi\Phi^\top PSD?

    9. State the Schur complement test for M=(ABB⊤C)M = \begin{pmatrix} A & B \\ B^\top & C \end{pmatrix}.

    10. What does A⪯BA \preceq B mean in the Loewner order?

    Open the review →

    9. Interview angle #

    • "How do you check that a matrix is PD in practice?" — Try a Cholesky factorization: about n3/3n^3/3 flops, and it fails exactly when a pivot is ≤0\le 0. Use eigvalsh if you need the margin λmin⁡\lambda_{\min}. Never use det⁡\det alone.
    • "My GP kernel matrix fails Cholesky. Why, and what do you do?" — It is numerically singular (close inputs, a very smooth kernel). Add jitter εI\varepsilon I: this moves it up in the Loewner order and lowers its condition number.
    • "Derive the conditional of a Gaussian." — Block-eliminate the covariance: the conditional mean is μb+ΣbaΣaa−1(xa−μa)\mu_b + \Sigma_{ba}\Sigma_{aa}^{-1}(x_a - \mu_a) and the conditional covariance is the Schur complement Σbb−ΣbaΣaa−1Σab\Sigma_{bb} - \Sigma_{ba}\Sigma_{aa}^{-1}\Sigma_{ab}.
    • "Is the sum of two PD matrices PD? The product?" — The sum, yes. The product ABAB is usually not symmetric, but its eigenvalues are real and positive: ABAB is similar to A1/2BA1/2≻0A^{1/2} B A^{1/2} \succ 0.

    10. Practice #

    The notebook for this lesson runs in Colab. It has five exercises, each with a check cell and a folded solution:

    1. Sample covariance of a real dataset (load_iris): build it from the centered data, check that it is PSD, and see the rank limit N−1N - 1.
    2. The five tests as functions (is_pd_eigen, is_pd_minors, elimination_pivots, …), checked to agree on random PD and non-PD matrices.
    3. Write cholesky column by column and make it report the step where it fails.
    4. Sample correlated Gaussians with X=1μ⊤+ZL⊤X = \mathbf{1}\mu^\top + ZL^\top, and check the sample covariance.
    5. loewner_leq(A, B): ridge (S⪯S+λIS \preceq S + \lambda I), the posterior–prior pair, and an incomparable pair.

    A demo section checks the Schur complement test and the Gaussian conditioning formula by sampling.

    11. Watch and read #

    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    Open on YouTube · the player loads from youtube-nocookie.com when you press play
    Open on YouTube · the player loads from youtube-nocookie.com when you press play