Part II — Linear Algebra & Matrix Decompositions · Chapter 6

Positive semi-definite matrices & covariance

Hook

Every real dataset has a covariance matrix, and every real covariance matrix shares one strange property: no matter which direction you measure variance along, you never get a negative number. That's not a coincidence — it's baked into what "variance" means, and it has a name: positive semi-definite.

Intuition

Each bar is vMvv^\top M v at a different direction vv. For the covariance matrix, every bar stays on the positive side no matter which direction you check. Switch to the other matrix and watch one bar cross to the negative side — proof that matrix could never be a real covariance matrix.

Formalize

A symmetric matrix MM is positive semi-definite (PSD) if its quadratic form never goes negative:

vMv0for every vector vv^\top M v \geq 0 \quad \text{for every vector } v
  • MM — a symmetric matrix (so M=MM=M^\top).
  • vv — any vector; the condition must hold for all of them, not just some.
  • vMvv^\top M v — the quadratic form: a single number measuring how MM acts along direction vv.
  1. Why covariance matrices are always PSD

    For a covariance matrix CC, vCvv^\top C v is exactly the variance of the data projected onto direction vv — and variance, being an average of squared numbers, can never be negative.

  2. What it means for the eigenvalues

    MM is PSD if and only if every eigenvalue of MM is 0\geq 0. Along an eigenvector vv, vMv=λv2v^\top M v = \lambda\|v\|^2, so a negative eigenvalue immediately produces a negative quadratic form there.

  3. Not every symmetric matrix qualifies

    Symmetry alone isn't enough — a symmetric matrix with even one negative eigenvalue fails the test, and could never arise as an actual covariance matrix of real data.

Play

covariance C = [[5,3],[3,5]]

not-PSD M = [[1,2],[2,1]]

Same eight directions, both matrices. The covariance matrix's bars all sit at or above zero; the other matrix's bars straddle it. That's the entire PSD test, run by hand, eight times.

Worked example

Four mean-centered points (3,1),(1,3),(3,1),(1,3)(3,1), (1,3), (-3,-1), (-1,-3) give the covariance matrix C=(5335)C=\begin{pmatrix}5&3\\3&5\end{pmatrix} (population covariance, dividing by n=4n=4):

  1. Variance along the x-axis

    v=(1,0)v=(1,0): vCv=1(51+30)+0()=5v^\top C v = 1(5\cdot1+3\cdot0)+0(\cdot) = 5 — matches Var(x)=5\mathrm{Var}(x)=5 directly.

  2. Variance along the direction of maximum spread

    v=(12,12)v=(\tfrac{1}{\sqrt2},\tfrac{1}{\sqrt2}): expanding vCv=5x2+6xy+5y2v^\top C v = 5x^2+6xy+5y^2 with x2=y2=xy=0.5x^2=y^2=xy=0.5 gives 2.5+3+2.5=82.5+3+2.5=8 — this is CC's top eigenvalue, and (1,1)(1,1) its eigenvector.

  3. Confirm PSD-ness at the minimum-variance direction too

    v=(12,12)v=(\tfrac{1}{\sqrt2},-\tfrac{1}{\sqrt2}): still x2=y2=0.5x^2=y^2=0.5, but now xy=0.5xy=-0.5 since the two components have opposite signs. Substituting into 5x2+6xy+5y25x^2+6xy+5y^2: 5(0.5)+6(0.5)+5(0.5)=2.53+2.5=25(0.5)+6(-0.5)+5(0.5) = 2.5-3+2.5=2 — still positive. 88 and 22 are CC's two eigenvalues; both positive, so CC is (strictly) positive definite.

Checkpoint

M = [[1,2],[2,1]] is symmetric but NOT positive semi-definite. Compute vTMv by hand at each candidate direction and click the one where it goes negative — that's your proof.

Pick an angle to try it
Summary
vMv0for every vector vv^\top M v \geq 0 \quad \text{for every vector } v

Positive semi-definiteness is what separates "a matrix that could plausibly be a covariance matrix" from "a matrix that never could be" — and it reduces entirely to a sign check on eigenvalues. This matters beyond statistics: kernel matrices in SVMs, Hessians at a true minimum, and Gram matrices in optimization all have to be PSD for the same underlying reason, and the low-rank and SVD chapters ahead lean directly on this eigenvalue-sign machinery.