Positive Semidefinite and Positive Definite Matrices
A symmetric matrix is positive definite when is positive for every nonzero . 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 be a real symmetric matrix. The number is the quadratic form of at .
| Name | Condition for every | Eigenvalues |
|---|---|---|
| positive definite (PD) | ||
| positive semidefinite (PSD) | ||
| negative definite | ||
| indefinite | takes both signs | , |
Why the eigenvalue test works. By the spectral theorem, . Put , which is nonzero exactly when is. Then
This is positive for all exactly when every .
Positive definite matrices are precisely the matrices for which is an inner product.
Four equivalent tests
For a real symmetric , each of these is equivalent to " is positive definite":
- for all .
- All eigenvalues are positive.
- All leading principal minors are positive: of the top-left blocks (Sylvester's criterion).
- for some with independent columns. The Cholesky factorization , with lower triangular and positive diagonal, exists.
For semidefinite matrices the minor test needs all principal minors , not just the leading ones, which is a classic trap.
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]]
is positive definite, is indefinite and is positive semidefinite ().
Gram matrices are always PSD
For any matrix , the matrix is symmetric and
so is PSD, and PD exactly when only for (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 , the second-order Taylor expansion around a point is
where is the symmetric Hessian matrix of second partial derivatives. At a critical point () the quadratic form of decides the shape:
| 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, is convex when 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.
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.choleskyfor the failing case: in the in-browser (Pyodide) build,np.linalg.choleskymay 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 operations, half of LU, and fails exactly when the matrix is not positive definite.
In software
- Optimization. Newton's method solves ; when is PD the step goes downhill, and Cholesky solves the system (Gradient Descent).
- Statistics. Covariance matrices are PSD. Sampling from a multivariate normal uses with .
- 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 positive definite?
Answer
Yes: leading minors 3 and are positive.
Solution
Sylvester's criterion: and . You can also complete the square, , which is positive unless ; or check the eigenvalues , both positive.
Exercise 2: For which ?
For which is positive definite?
Answer
.
Solution
The first minor is . The determinant must be positive, so .
Exercise 3: Classify a critical point
has critical points . Classify them using the Hessian.
Answer
is a local minimum, is a saddle point.
Solution
Exercise 4: Cholesky by hand (code)
Find with , then confirm with NumPy.
Answer
.
Solution
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
has leading minors 0 and 0. Is it PSD?
Answer
No. Its eigenvalues are 0 and −1, and at .
Solution
Nonnegative leading minors are not enough for semidefiniteness: the principal minor obtained from the second row and column alone is . Check all principal minors, or the eigenvalues.
Test yourself
A symmetric matrix has eigenvalues 3, 0.5 and 0. It is…
- positive definite
- positive semidefinite but not definite
- indefinite
- negative definite
At a critical point the Hessian is indefinite. The point is…
- a local minimum
- a local maximum
- a saddle point
- impossible to have
Why is always positive semidefinite?
- Because it is diagonal
- Because
- Because is square
- It is not always PSD