Foundations to Frontier
Tests
A. Mathematical Foundations › A2 Linear Algebra › Decompositions

Positive Definite and Semidefinite Matrices

Matrices whose quadratic form is a bowl. They are covariances, kernels, energies and Hessians at minima, and they power Gaussian models, convex optimization, Kalman filters and robot controllers.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Bowls, saddles and domes

Drop a marble into a bowl and it rolls to the bottom, whichever side it starts from. On a saddle (like a horse’s saddle or a crisp) it rolls off: uphill in one direction, downhill in another. On a dome it rolls away everywhere.

Certain symmetric matrices describe bowls. They’re called positive definite. Their “energy” is positive in every direction, so there’s exactly one lowest point.

Move the sliders and watch the shape change:

The shape of xᵀSx: bowl, valley, saddle or dome?
S = [[2.0, 0.8], [0.8, 1.0]] · eigenvalues 2.44, 0.56 · det 1.36 → positive definite: a bowl, unique minimum at 0
Blue = positive, orange = negative; stripes are level sets. Positive definite ⇔ both eigenvalues > 0 ⇔ a > 0 and det > 0.
Why AI cares

Training an AI means rolling a marble downhill on a very bumpy landscape. Near the bottom of a valley, the landscape looks like a bowl described by a positive definite matrix. That’s how we know we’ve found a minimum.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Where does a marble end up in a bowl?
  2. 2. Energy x² + y² at the point (3, 4)?
  3. 3. On a saddle, how many directions curve upwards (in 2D)?

Level 1: Beginner

★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.

The quadratic form

For a symmetric matrix SS, the quadratic form is the number x⊤Sx\mathbf x^\top S\mathbf x. In 2D, with S=(abbc)S = \begin{pmatrix}a&b\\b&c\end{pmatrix}:

x⊤Sx=ax2+2bxy+cy2\mathbf x^\top S\mathbf x = ax^2 + 2bxy + cy^2

For example, S=diag⁡(2,3)S = \operatorname{diag}(2,3) gives 2x2+3y22x^2 + 3y^2, which equals 5 at (1,1)(1,1).

The definitions

Name Condition for all x≠0\mathbf x\ne\mathbf 0 Shape
positive definite (PD), S≻0S \succ 0 x⊤Sx>0\mathbf x^\top S\mathbf x > 0 bowl
positive semidefinite (PSD), S⪰0S \succeq 0 x⊤Sx≥0\mathbf x^\top S\mathbf x \ge 0 bowl or flat valley
negative definite <0< 0 dome
indefinite takes both signs saddle
📝 Quick check (Level 1)
0/3 answered
  1. 1. Is diag(2, 3) positive definite?
  2. 2. diag(2, −1) is…
  3. 3. xᵀSx for S = [[2,1],[1,2]] and x = (1, −1)?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Tests for positive definiteness

For a symmetric SS, the following are equivalent:

  1. x⊤Sx>0\mathbf x^\top S\mathbf x > 0 for all x≠0\mathbf x \ne \mathbf 0;
  2. all eigenvalues are positive (spectral theorem: x⊤Sx=∑λiyi2\mathbf x^\top S\mathbf x = \sum\lambda_iy_i^2);
  3. all leading principal minors are positive (Sylvester’s criterion). For 2×2: a>0a > 0 and ac−b2>0ac - b^2 > 0;
  4. S=R⊤RS = R^\top R for some RR with independent columns;
  5. a Cholesky factorization S=LL⊤S = LL^\top exists, with positive diagonal (A2.3-4).

For semi-definite, replace > with ≥. Sylvester’s criterion then needs all principal minors, not just the leading ones.

Example. (4223)\begin{pmatrix}4&2\\2&3\end{pmatrix}: the minors are 4 and 12−4=812 - 4 = 8, both positive, so it’s PD. In contrast, (1221)\begin{pmatrix}1&2\\2&1\end{pmatrix} has eigenvalues 3 and −1, so it’s indefinite.

🐍 Exercise 1: test definiteness two ways
Classify a symmetric matrix by its eigenvalues, and test PD with Sylvester's criterion. The tests check that both agree on 200 random matrices.

Where PSD matrices come from

Source Why it’s PSD
Gram matrices X⊤XX^\top X v⊤X⊤Xv=∥Xv∥2≥0\mathbf v^\top X^\top X\mathbf v = \lVert X\mathbf v\rVert^2 \ge 0
Covariance matrices Σ\Sigma v⊤Σv=Var⁡(v⊤x)≥0\mathbf v^\top\Sigma\mathbf v = \operatorname{Var}(\mathbf v^\top\mathbf x) \ge 0
Kernel matrices Kij=k(xi,xj)K_{ij} = k(\mathbf x_i,\mathbf x_j) the definition of a valid kernel (B3)
Hessians at a minimum second-order condition for a local minimum (A6)
Graph Laplacians x⊤Lx=∑(i,j)(xi−xj)2≥0\mathbf x^\top L\mathbf x = \sum_{(i,j)}(x_i - x_j)^2 \ge 0
Mass and inertia matrices of robots kinetic energy 12q˙⊤M(q)q˙>0\tfrac12\dot{\mathbf q}^\top M(\mathbf q)\dot{\mathbf q} > 0 (R4)

Ellipsoids and Mahalanobis distance

For PD Σ\Sigma, the set {x:x⊤Σ−1x≤1}\{\mathbf x : \mathbf x^\top\Sigma^{-1}\mathbf x \le 1\} is an ellipsoid. Its axes point along the eigenvectors, with lengths λi\sqrt{\lambda_i}. The Mahalanobis distance (x−μ)⊤Σ−1(x−μ)\sqrt{(\mathbf x-\boldsymbol\mu)^\top\Sigma^{-1}(\mathbf x-\boldsymbol\mu)} measures how unusual a point is taking correlations into account. It’s the basis of uncertainty ellipses in robot localization, and of anomaly detection on telemetry (Practice Code 5).

📝 Quick check (Level 2)
0/3 answered
  1. 1. [[4, 2], [2, 3]]: leading minors are 4 and…
  2. 2. The Gram matrix XᵀX is always…
  3. 3. Hessian [[2, 1], [1, 2]] at a critical point means…

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Why the tests are equivalent

Theorem

For symmetric SS: S≻0S\succ0 ⟺ all λi>0\lambda_i > 0 ⟺ S=R⊤RS = R^\top R with RR having independent columns.

Proof. Write S=QΛQ⊤S = Q\Lambda Q^\top and y=Q⊤x\mathbf y = Q^\top\mathbf x. Then x⊤Sx=∑λiyi2\mathbf x^\top S\mathbf x = \sum\lambda_iy_i^2, which is positive for all y≠0\mathbf y\ne0 iff every λi>0\lambda_i > 0. If the λi>0\lambda_i > 0, take R=Λ1/2Q⊤R = \Lambda^{1/2}Q^\top. Conversely, x⊤R⊤Rx=∥Rx∥2>0\mathbf x^\top R^\top R\mathbf x = \lVert R\mathbf x\rVert^2 > 0 whenever Rx≠0R\mathbf x \ne 0, which independence guarantees for x≠0\mathbf x\ne0. ∎

Closure properties

  • If A,B⪰0A, B \succeq 0, then A+B⪰0A + B \succeq 0, and cA⪰0cA \succeq 0 for c≥0c \ge 0. PSD matrices form a convex cone, the setting of semidefinite programming (A6.2).
  • PD+PSD=PDPD + PSD = PD. That’s why adding “jitter” ϵI\epsilon I fixes numerically singular kernel matrices, and why ridge regression uses X⊤X+λIX^\top X + \lambda I.
  • C⊤SC⪰0C^\top SC \succeq 0 for any CC (congruence). Covariances stay PSD under linear maps: Cov⁡(Ax)=AΣA⊤\operatorname{Cov}(A\mathbf x) = A\Sigma A^\top.
  • Hadamard products of PSD matrices are PSD (Schur, A2.2-6).

The Schur-complement test

Theorem

(ABB⊤C)≻0\begin{pmatrix}A&B\\B^\top&C\end{pmatrix}\succ0 ⟺ A≻0A\succ0 and C−B⊤A−1B≻0C - B^\top A^{-1}B \succ 0.

For example, (422c)≻0\begin{pmatrix}4&2\\2&c\end{pmatrix}\succ0 iff c−1>0c - 1 > 0. This test converts nonlinear matrix inequalities into linear ones (LMIs). That’s the key trick behind proving stability of robot controllers with Lyapunov functions, and behind robust control design (S2, S3).

Exercise 3.1: Prove that every PD matrix is invertible

If Sx=0S\mathbf x = \mathbf 0, then x⊤Sx=0\mathbf x^\top S\mathbf x = 0, so x=0\mathbf x = \mathbf 0. The kernel is trivial, so SS is invertible. Also, S−1S^{-1} is PD, with eigenvalues 1/λi>01/\lambda_i > 0.

📝 Quick check (Level 3)
0/3 answered
  1. 1. [[1, 1], [1, 1]] is…
  2. 2. PD + PSD is always…
  3. 3. [[4, 2], [2, c]] is PD exactly when c >…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Sampling and estimation with Gaussians

A Gaussian N(μ,Σ)\mathcal N(\boldsymbol\mu,\Sigma) needs Σ⪰0\Sigma \succeq 0. To sample it, factor Σ=LL⊤\Sigma = LL^\top (Cholesky) and set x=μ+Lz\mathbf x = \boldsymbol\mu + L\mathbf z with z∼N(0,I)\mathbf z\sim\mathcal N(0,I). This trick is used everywhere: Gaussian processes, VAEs’ reparameterization (H3), particle and unscented Kalman filters for robot state estimation (T1), and domain randomization in simulation (V1).

🐍 Exercise 2 (research): sample a correlated Gaussian with Cholesky
Draw samples x = μ + Lz, check the empirical covariance matches Σ, and check that squared Mahalanobis distances average 2 in 2-D.

Keeping matrices PSD in learning systems

Models that predict covariances or kernels must output valid PSD matrices. Common parameterizations:

  • predict a lower-triangular LL with a positive diagonal (via softplus or exp) and use LL⊤LL^\top;
  • predict eigenvalues through a positive function, and an orthogonal basis.

This shows up in learned uncertainty for robot perception, in heteroscedastic regression (I1), and in learned metrics for SLAM. In optimization, positive definite preconditioners (Adam’s diagonal, natural-gradient Fisher matrices, Shampoo) are what make second-order ideas practical (A6).

Certifying robot safety with PSD constraints

A Lyapunov function V(x)=x⊤PxV(\mathbf x) = \mathbf x^\top P\mathbf x with P≻0P\succ0 proves that a linear system x˙=Ax\dot{\mathbf x} = A\mathbf x is stable if A⊤P+PA≺0A^\top P + PA \prec 0 (Lyapunov, 1892). Searching for such a PP is a semidefinite program. Boyd et al. (1994) showed that a huge range of control problems can be written as such linear matrix inequalities and solved efficiently. Today they’re used to certify neural-network controllers (S6, M2).

References

  1. J. J. Sylvester (1852). “A demonstration of the theorem that every homogeneous quadratic polynomial is reducible by real orthogonal substitutions to the form of a sum of positive and negative squares.” Philosophical Magazine, 4.
  2. A. M. Lyapunov (1892). The General Problem of the Stability of Motion. (English translation: International Journal of Control, 1992.)
  3. P. C. Mahalanobis (1936). “On the generalised distance in statistics.” Proceedings of the National Institute of Sciences of India, 2.
  4. S. Boyd, L. El Ghaoui, E. Feron, V. Balakrishnan (1994). Linear Matrix Inequalities in System and Control Theory. SIAM.
  5. C. Rasmussen and C. Williams (2006). Gaussian Processes for Machine Learning. MIT Press. Appendix A.
  6. R. Bhatia (2007). Positive Definite Matrices. Princeton University Press.