Last updated 13 November 2026
What is a positive definite matrix?
A symmetric matrix is positive definite if for every nonzero vector , the quadratic form . Intuitively, this means the matrix always "curves upward" and has a unique minimum at the origin. On TensorTonic you implement Cholesky decomposition and solve ridge regression's positive definite system from scratch, with tests that check your output.
Positive definite matrices are the "well behaved" matrices in optimization. They guarantee that gradient descent will find a unique global minimum. They appear everywhere: covariance matrices, Hessians of convex functions, and kernel matrices.
The Core Property
for all . This single condition has profound consequences for optimization, statistics, and numerical stability.
The Quadratic Form
The expression is called the quadratic form associated with . For a 2×2 symmetric matrix, it expands to:
Positive Definite
Bowl shape. Unique minimum at origin. All level curves are ellipses.
Indefinite
Saddle shape. Neither max nor min at origin. Level curves are hyperbolas.
Negative Definite
Inverted bowl. Unique maximum at origin. All level curves are ellipses.
Interactive Visualization
Adjust the symmetric matrix entries and watch the level curve of the quadratic form change. The arrows show gradient directions. Notice how positive definite matrices create elliptical level curves that all point inward.
Energy Surface
Plotting z = xᵀAx in 3D
Positive Definite
Bowl shape (Convex). Unique global minimum.
Four tests for definiteness
There are several equivalent ways to check if a symmetric matrix is positive definite:
- Eigenvalue Test: All eigenvalues are strictly positive.
- Sylvester's Criterion: All leading principal minors (upper-left determinants) are positive.
- Cholesky Test: The Cholesky decomposition exists with positive diagonal entries.
- Pivot Test: In LU decomposition, all pivots are positive.
For 2×2
is PD if and .
Computational
In practice, attempt Cholesky factorization. If it succeeds, the matrix is PD.
Worked example: running all four tests
Take . By hand, Sylvester's criterion gives leading minors and , so is positive definite. Compare , whose second minor is , so it is not. The code runs the same check four ways:
import numpy as np
def definiteness_tests(A):
"""Run the four positive definiteness tests on a symmetric matrix."""
eig = np.all(np.linalg.eigvalsh(A) > 0)
minors = np.all([np.linalg.det(A[:k, :k]) > 0 for k in range(1, len(A) + 1)])
try:
np.linalg.cholesky(A)
chol = True
except np.linalg.LinAlgError:
chol = False
x = np.random.default_rng(0).standard_normal((10_000, len(A)))
quad = np.all(np.einsum('ni,ij,nj->n', x, A, x) > 0) # x^T A x on random x
return eig, minors, chol, quad
for name, A in [("A", np.array([[4.0, 2.0], [2.0, 3.0]])),
("B", np.array([[1.0, 3.0], [3.0, 1.0]]))]:
eig, minors, chol, quad = definiteness_tests(A)
print(f"{name}: eigenvalues {np.round(np.linalg.eigvalsh(A), 3)}")
print(f" eigen={eig} minors={minors} cholesky={chol} quadratic form={quad}")
L = np.linalg.cholesky(np.array([[4.0, 2.0], [2.0, 3.0]]))
print("Cholesky factor of A:
", np.round(L, 3))A: eigenvalues [1.438 5.562] eigen=True minors=True cholesky=True quadratic form=True B: eigenvalues [-2. 4.] eigen=False minors=False cholesky=False quadratic form=False Cholesky factor of A: [[2. 0. ] [1. 1.414]]
All four tests agree, as they must for a symmetric matrix. has one negative eigenvalue, so its quadratic form is a saddle: gives . The random quadratic-form check can only ever disprove definiteness, never prove it, which is why libraries use the eigenvalue or Cholesky test instead. Cholesky is the cheapest of the conclusive tests, at roughly operations.
Cholesky Decomposition
A positive definite matrix can be uniquely factored as , where is a lower triangular matrix with positive diagonal entries. This is the "square root" of a matrix.
Why Cholesky?
- Speed: 2× faster than LU because we exploit symmetry.
- Stability: No pivoting needed (guaranteed stable for PD).
- Sampling: To sample from , compute from , then where .
The Definiteness Spectrum
The classification of a symmetric matrix depends on the signs of its eigenvalues:
| Type | Eigenvalues | Quadratic Form | Optimization |
|---|---|---|---|
| Positive Definite | All λ > 0 | Unique minimum | |
| Positive Semidefinite | All λ ≥ 0 | Minimum subspace | |
| Indefinite | Mixed signs | Both + and - | Saddle point |
| Negative Semidefinite | All λ ≤ 0 | Maximum subspace | |
| Negative Definite | All λ < 0 | Unique maximum |
Why positive definiteness matters for optimisation and ML
At a point where the gradient is zero, a positive definite Hessian means the loss curves upward in every direction, so the point is a strict local minimum. If the Hessian is positive definite everywhere, the function is strictly convex and that minimum is the only one. This is the second-derivative test from calculus, extended to many dimensions, and it is how you tell a minimum from a saddle point.
Ridge regression is a clean example. Its solution is . The matrix is only positive semidefinite and can be singular when features are collinear, but adding with raises every eigenvalue by . The system becomes positive definite, so it always has exactly one solution and can be solved with a Cholesky factorization. Newton's method relies on the same property: its step only points downhill when is positive definite.
Covariance Matrices
Sample covariance matrices are always positive semidefinite. In Gaussians, we need PD covariance for the density to be well defined.
Convex Optimization
A function is convex if its Hessian is PSD everywhere. This guarantees gradient descent converges to the global minimum.
Kernel Matrices
A valid kernel function must produce PSD Gram matrices. This is Mercer's condition, ensuring the implicit feature space is well defined.
Gaussian Processes
GP priors require PD covariance matrices for sampling. Cholesky is used to generate correlated samples from a GP posterior.
Frequently asked questions about positive definite matrices
How do you check if a matrix is positive definite?
A symmetric matrix is positive definite if all its eigenvalues are strictly positive, which is equivalent to all leading principal minors being positive or a Cholesky factorization existing. In practice, libraries attempt a Cholesky factorization, and if it succeeds the matrix is positive definite.
What is the difference between positive definite and positive semidefinite?
A positive definite matrix has all eigenvalues greater than zero and xᵀAx > 0 for every nonzero x, while a positive semidefinite matrix allows zero eigenvalues and xᵀAx ≥ 0. Sample covariance matrices are always positive semidefinite, and adding λI with λ > 0, as ridge regression does, makes such a matrix positive definite.
Practice this
On TensorTonic you implement this from scratch and test it in the browser.
- Cholesky Decomposition: factor yourself; it fails exactly when is not positive definite.
- Calculate Eigenvalues of a Matrix: the eigenvalue test.
- Ridge Regression: solve the positive definite system from the section above.
- Newton's Method: an optimizer that needs a positive definite Hessian to move downhill.