TExcelTAD
Home › Linear Algebra & Matrix Theory › Positive Semidefinite and Positive Definite Matrices

Positive Semidefinite and Positive Definite Matrices

A symmetric matrix is positive definite when xTAx\mathbf{x}^TA\mathbf{x} is positive for every nonzero x\mathbf{x}. These are the matrices that define inner products, the Hessians of bowl-shaped functions, and the covariance matrices of statistics, and they have their own fast factorization, the Cholesky decomposition.

Definitions

Let AA be a real symmetric n×nn \times n matrix. The number xTAx\mathbf{x}^TA\mathbf{x} is the quadratic form of AA at x\mathbf{x}.

Name Condition for every x≠0\mathbf{x} \ne \mathbf{0} Eigenvalues
positive definite (PD) xTAx>0\mathbf{x}^TA\mathbf{x} > 0 all>0\text{all} > 0
positive semidefinite (PSD) xTAx≥0\mathbf{x}^TA\mathbf{x} \ge 0 all≥0\text{all} \ge 0
negative definite xTAx<0\mathbf{x}^TA\mathbf{x} < 0 all<0\text{all} < 0
indefinite takes both signs some>0\text{some} > 0, some<0\text{some} < 0

Why the eigenvalue test works. By the spectral theorem, A=QΛQTA = Q\Lambda Q^T. Put y=QTx\mathbf{y} = Q^T\mathbf{x}, which is nonzero exactly when x\mathbf{x} is. Then

xTAx=xTQΛQTx=yTΛy=λ1y12+λ2y22+⋯+λnyn2\mathbf{x}^TA\mathbf{x} = \mathbf{x}^TQ\Lambda Q^T\mathbf{x} = \mathbf{y}^T\Lambda\mathbf{y} = \lambda_1y_1^2 + \lambda_2y_2^2 + \cdots + \lambda_ny_n^2

This is positive for all y≠0\mathbf{y} \ne \mathbf{0} exactly when every λi>0\lambda_i > 0.

Positive definite matrices are precisely the matrices for which ⟨u,v⟩=uTAv\langle \mathbf{u}, \mathbf{v} \rangle = \mathbf{u}^TA\mathbf{v} is an inner product.

Four equivalent tests

For a real symmetric AA, each of these is equivalent to "AA is positive definite":

  1. xTAx>0\mathbf{x}^TA\mathbf{x} > 0 for all x≠0\mathbf{x} \ne \mathbf{0}.
  2. All eigenvalues are positive.
  3. All leading principal minors are positive: det⁡\det of the top-left 1×1,2×2,…,n×n1 \times 1, 2 \times 2, \ldots, n \times n blocks (Sylvester's criterion).
  4. A=RTRA = R^TR for some RR with independent columns. The Cholesky factorization A=LLTA = LL^T, with LL lower triangular and positive diagonal, exists.

For semidefinite matrices the minor test needs all principal minors ≥0\ge 0, not just the leading ones, which is a classic trap.

python · try it yourself
from sympy import Matrix

def report(name, A):
    minors = [A[:k, :k].det() for k in range(1, A.rows + 1)]
    print(f"{name}: eigenvalues {sorted(A.eigenvals(multiple=True))}, leading minors {minors}")

report("A", Matrix([[2, -1, 0], [-1, 2, -1], [0, -1, 2]]))
report("B", Matrix([[1, 2], [2, 1]]))
report("C", Matrix([[1, 1], [1, 1]]))
L = Matrix([[2, -1, 0], [-1, 2, -1], [0, -1, 2]]).cholesky()
print("Cholesky L of A:", L.tolist())
A: eigenvalues [2 - sqrt(2), 2, sqrt(2) + 2], leading minors [2, 3, 4]
B: eigenvalues [-1, 3], leading minors [1, -3]
C: eigenvalues [0, 2], leading minors [1, 0]
Cholesky L of A: [[sqrt(2), 0, 0], [-sqrt(2)/2, sqrt(6)/2, 0], [0, -sqrt(6)/3, 2*sqrt(3)/3]]

AA is positive definite, BB is indefinite and CC is positive semidefinite (C(1,−1)=0C(1, -1) = 0).

Gram matrices are always PSD

For any m×nm \times n matrix MM, the matrix MTMM^TM is symmetric and

xT(MTM)x=(Mx)T(Mx)=∥Mx∥2≥0\mathbf{x}^T(M^TM)\mathbf{x} = (M\mathbf{x})^T(M\mathbf{x}) = \lVert M\mathbf{x} \rVert^2 \ge 0

so MTMM^TM is PSD, and PD exactly when Mx=0M\mathbf{x} = \mathbf{0} only for x=0\mathbf{x} = \mathbf{0} (independent columns). That is why the normal equations of least squares have a unique solution, and why every sample covariance matrix is PSD.

Hessians and convexity

For a twice-differentiable function f ⁣:Rn→Rf\colon \mathbb{R}^n \to \mathbb{R}, the second-order Taylor expansion around a point p\mathbf{p} is

f(p+h)≈f(p)+∇f(p)⋅h+12hTH(p)hf(\mathbf{p} + \mathbf{h}) \approx f(\mathbf{p}) + \nabla f(\mathbf{p}) \cdot \mathbf{h} + \frac{1}{2} \mathbf{h}^T H(\mathbf{p}) \mathbf{h}

where HH is the symmetric Hessian matrix of second partial derivatives. At a critical point (∇f=0\nabla f = \mathbf{0}) the quadratic form of HH decides the shape:

HH at a critical point Shape Conclusion
positive definite bowl local minimum
negative definite dome local maximum
indefinite saddle neither
only semidefinite flat direction test inconclusive

This is the second derivative test of multivariable calculus in matrix language. More globally, ff is convex when H(x)H(\mathbf{x}) is PSD at every point, and then every local minimum is a global minimum. That is what makes least squares, logistic regression and ridge regression easy optimization problems, while neural network losses (with indefinite Hessians full of saddles) are hard.

python · try it yourself
import numpy as np

def classify(H):
    w = np.linalg.eigvalsh(H)
    kind = ("minimum" if w.min() > 0 else "maximum" if w.max() < 0
            else "saddle" if w.min() < 0 < w.max() else "inconclusive")
    return np.round(w, 4), kind

# f(x, y) = x^2 + x*y + 2*y^2 and g(x, y) = x^2 - 3*x*y + y^2, both critical at 0
print("f:", *classify(np.array([[2.0, 1.0], [1.0, 4.0]])))
print("g:", *classify(np.array([[2.0, -3.0], [-3.0, 2.0]])))

A = np.array([[4.0, 2.0], [2.0, 3.0]])
L = np.linalg.cholesky(A)
print("Cholesky L =", np.round(L, 4).tolist(), " LL^T = A:", np.allclose(L @ L.T, A))
import scipy.linalg
try:
    scipy.linalg.cholesky(np.array([[1.0, 2.0], [2.0, 1.0]]), lower=True)
except np.linalg.LinAlgError as e:
    print("not PD:", e)
f: [1.5858 4.4142] minimum
g: [-1.  5.] saddle
Cholesky L = [[2.0, 0.0], [1.0, 1.4142]]  LL^T = A: True
not PD: 2-th leading minor of the array is not positive definite

Note: The example uses scipy.linalg.cholesky for the failing case: in the in-browser (Pyodide) build, np.linalg.cholesky may not raise an error for a matrix that is not positive definite, while SciPy's version reliably does.

Tip: The cheapest practical PD test is to attempt a Cholesky factorization: it costs about n3/3n^3/3 operations, half of LU, and fails exactly when the matrix is not positive definite.

In software

  • Optimization. Newton's method solves H⋅step=−∇fH \cdot \text{step} = -\nabla f; when HH is PD the step goes downhill, and Cholesky solves the system (Gradient Descent).
  • Statistics. Covariance matrices are PSD. Sampling from a multivariate normal uses x=μ+Lz\mathbf{x} = \boldsymbol{\mu} + L\mathbf{z} with Σ=LLT\Sigma = LL^T.
  • Machine learning. A valid kernel for an SVM or Gaussian process must produce PSD Gram matrices.
  • Physics and games. Stiffness and mass matrices in finite-element and cloth simulations are PD; implicit integrators solve PD systems every frame.

Exercises

Exercise 1: Classify by minors

Is A=[3222]A = \begin{bmatrix} 3 & 2 \\ 2 & 2 \end{bmatrix} positive definite?

Answer

Yes: leading minors 3 and 6−4=26 - 4 = 2 are positive.

Solution

Sylvester's criterion: det⁡[3]=3>0\det[3] = 3 > 0 and det⁡A=3⋅2−2⋅2=2>0\det A = 3 \cdot 2 - 2 \cdot 2 = 2 > 0. You can also complete the square, xTAx=3x2+4xy+2y2=3(x+2y/3)2+23y2\mathbf{x}^TA\mathbf{x} = 3x^2 + 4xy + 2y^2 = 3(x + 2y/3)^2 + \frac{2}{3}y^2, which is positive unless x=y=0x = y = 0; or check the eigenvalues 5±172≈4.56,0.44\frac{5 \pm \sqrt{17}}{2} \approx 4.56, 0.44, both positive.

Exercise 2: For which kk?

For which kk is [1kk4]\begin{bmatrix} 1 & k \\ k & 4 \end{bmatrix} positive definite?

Answer

−2<k<2-2 < k < 2.

Solution

The first minor is 1>01 > 0. The determinant 4−k24 - k^2 must be positive, so k2<4k^2 < 4.

Exercise 3: Classify a critical point

f(x,y)=x3−3x+y2f(x, y) = x^3 - 3x + y^2 has critical points (±1,0)(\pm 1, 0). Classify them using the Hessian.

Answer

(1,0)(1, 0) is a local minimum, (−1,0)(-1, 0) is a saddle point.

Solution
∇f=(3x2−3,2y)=0  ⟹  x=±1, y=0H=[6x002](1,0) ⁣: H=diag⁡(6,2)positive definite→minimum(−1,0) ⁣: H=diag⁡(−6,2)indefinite→saddle\begin{aligned} \nabla f &= (3x^2 - 3, 2y) = \mathbf{0} \implies x = \pm 1,\ y = 0 \\ H &= \begin{bmatrix} 6x & 0 \\ 0 & 2 \end{bmatrix} \\ (1, 0)\colon\ H &= \operatorname{diag}(6, 2) && \text{positive definite} \to \text{minimum} \\ (-1, 0)\colon\ H &= \operatorname{diag}(-6, 2) && \text{indefinite} \to \text{saddle} \end{aligned}

Exercise 4: Cholesky by hand (code)

Find LL with LLT=[9335]LL^T = \begin{bmatrix} 9 & 3 \\ 3 & 5 \end{bmatrix}, then confirm with NumPy.

Answer

L=[3012]L = \begin{bmatrix} 3 & 0 \\ 1 & 2 \end{bmatrix}.

Solution
l112=9  ⟹  l11=3l21⋅l11=3  ⟹  l21=1l212+l222=5  ⟹  l22=2\begin{aligned} l_{11}^2 = 9 &\implies l_{11} = 3 \\ l_{21} \cdot l_{11} = 3 &\implies l_{21} = 1 \\ l_{21}^2 + l_{22}^2 = 5 &\implies l_{22} = 2 \end{aligned}
python · try it yourself
import numpy as np
print(np.linalg.cholesky(np.array([[9.0, 3.0], [3.0, 5.0]])).tolist())
[[3.0, 0.0], [1.0, 2.0]]

Exercise 5: Semidefinite trap

M=[000−1]M = \begin{bmatrix} 0 & 0 \\ 0 & -1 \end{bmatrix} has leading minors 0 and 0. Is it PSD?

Answer

No. Its eigenvalues are 0 and −1, and xTMx=−1\mathbf{x}^TM\mathbf{x} = -1 at x=(0,1)\mathbf{x} = (0, 1).

Solution

Nonnegative leading minors are not enough for semidefiniteness: the principal minor obtained from the second row and column alone is −1<0-1 < 0. Check all principal minors, or the eigenvalues.

Test yourself

A symmetric matrix has eigenvalues 3, 0.5 and 0. It is…

  1. positive definite
  2. positive semidefinite but not definite
  3. indefinite
  4. negative definite

At a critical point the Hessian is indefinite. The point is…

  1. a local minimum
  2. a local maximum
  3. a saddle point
  4. impossible to have

Why is MTMM^TM always positive semidefinite?

  1. Because it is diagonal
  2. Because xTMTMx=∥Mx∥2≥0\mathbf{x}^TM^TM\mathbf{x} = \lVert M\mathbf{x} \rVert^2 \ge 0
  3. Because MM is square
  4. It is not always PSD