PositiveSemidefiniteMatrixQ[m]
gives True if m is explicitly positive semidefinite, and False otherwise.
PositiveSemidefiniteMatrixQ
PositiveSemidefiniteMatrixQ[m]
gives True if m is explicitly positive semidefinite, and False otherwise.
Details and Options
- A matrix m is positive semidefinite if Re[Conjugate[x].m.x]≥0 for all vectors x. »
- PositiveSemidefiniteMatrixQ works for symbolic as well as numerical matrices.
- For approximate matrices, the option Tolerance->t can be used to indicate that all eigenvalues λ satisfying λ≤t λmax are taken to be zero where λmax is an eigenvalue largest in magnitude.
- The option Tolerance has Automatic as its default value.
Examples
open all close allBasic Examples (2)
Test if a 2×2 real matrix is explicitly positive semidefinite:
m = {{2, 0}, {0, 0}};PositiveSemidefiniteMatrixQ[m]This means that the quadratic form
for all vectors
:
Reduce[Subscript[∀, {Subscript[x, 1], Subscript[x, 2]}]{Subscript[x, 1], Subscript[x, 2]}.m.{Subscript[x, 1], Subscript[x, 2]} >= 0, {Subscript[x, 1], Subscript[x, 2]}, Reals]Visualize the values of the quadratic form:
Plot3D[{Subscript[x, 1], Subscript[x, 2]}.m.{Subscript[x, 1], Subscript[x, 2]}, {Subscript[x, 1], Subscript[x, 2]}∈Disk[], BoxRatios -> 1]Test if a 3×3 Hermitian matrix is positive semidefinite:
PositiveSemidefiniteMatrixQ[(| | | |
| ---------------- | -------------- | ---------------- |
| 5.42 | 3.26 + 0.643 I | -0.467 - 0.193 I |
| 3.26 - 0.643 I | 3.82 | 1.04 - 2.35 I |
| -0.467 + 0.193 I | 1.04 + 2.35 I | 4.88 |)]Scope (10)
Basic Uses (6)
Test if a real machine-precision matrix is explicitly positive semidefinite:
PositiveSemidefiniteMatrixQ[{{1.6, -0.8}, {-0.8, 0.4}}]Test if a complex matrix is positive semidefinite:
PositiveSemidefiniteMatrixQ[{{1, 2 I}, {-I, 3}}]Test if an exact matrix is positive semidefinite:
PositiveSemidefiniteMatrixQ[(| | | |
| - | ------- | -- |
| π | -5 | 2 |
| E | -3 | -3 |
| 5 | Sqrt[2] | 5 |)]Use PositiveSemidefiniteMatrixQ with an arbitrary-precision matrix:
m = RandomReal[5, {3, 3}, WorkingPrecision -> 15]A random matrix is typically not positive semidefinite:
PositiveSemidefiniteMatrixQ[m]Use PositiveSemidefiniteMatrixQ with a symbolic matrix:
PositiveSemidefiniteMatrixQ[{{0, a}, {b, 0}}]The matrix becomes positive semidefinite when
:
Block[{b = -Conjugate[a]}, PositiveSemidefiniteMatrixQ[{{0, a}, {b, 0}}]]PositiveSemidefiniteMatrixQ works efficiently with large numerical matrices:
m = RandomReal[1, {1000, 1000}];AbsoluteTiming[PositiveSemidefiniteMatrixQ[m]]a = m.m^;
AbsoluteTiming[PositiveSemidefiniteMatrixQ[a]]Special Matrices (4)
Use PositiveSemidefiniteMatrixQ with sparse matrices:
SparseArray[{{i_, i_} -> 2., {i_, j_} /; Abs[i - j] == 1 -> -1.}, {10, 10}, 0.]PositiveSemidefiniteMatrixQ[%]Use PositiveSemidefiniteMatrixQ with structured matrices:
SymmetrizedArray[{{1, 1} -> 5, {1, 2} -> 11, {2, 2} -> 25}, {2, 2}, Symmetric[All]]PositiveSemidefiniteMatrixQ[%]The identity matrix is positive semidefinite:
PositiveSemidefiniteMatrixQ[IdentityMatrix[5]]HilbertMatrix is positive semidefinite:
PositiveSemidefiniteMatrixQ[HilbertMatrix[5]]Options (1)
Tolerance (1)
Generate a real-valued diagonal matrix with some random perturbation of order 10-12:
SeedRandom[5];
m = {{2, 0, 0}, {0, 1, 0}, {0, 0, 0}} + 10 ^ -12 * DiagonalMatrix[RandomReal[{-10, -1}, 3]]PositiveSemidefiniteMatrixQ[m]Adjust the option Tolerance to accept matrices as positive semidefinite:
PositiveSemidefiniteMatrixQ[m, Tolerance -> 10 ^ -12]Applications (13)
The Geometry and Algebra of Positive Semidefinite Matrices (5)
Consider a real, positive semidefinite 2×2 matrix and its associated real quadratic
:
m = (| | |
| -- | -- |
| 3 | -1 |
| -1 | 3 |);
PositiveSemidefiniteMatrixQ[m]q[x_, y_] := {x, y}.m.{x, y}Because
is positive definite, the level sets are ellipses:
ContourPlot[q[x, y], {x, -2, 2}, {y, -2, 2}]The plot of
will be an upward-facing elliptic paraboloid:
Plot3D[q[x, y], {x, y}∈RotationTransform[π / 4][Disk[{0, 0}, {2, Sqrt[2]}]], MeshFunctions -> {#3&}, BoxRatios -> 1]However, the ellipses can be degenerate, turning into lines:
m = (| | |
| -- | -- |
| 3 | -3 |
| -3 | 3 |);
PositiveSemidefiniteMatrixQ[m]ContourPlot[q[x, y], {x, -2, 2}, {y, -2, 2}]The plot of
is then a cylinder over a parabola:
Plot3D[q[x, y], {x, y}∈RotationTransform[π / 4][Rectangle[{-1, -1}, {1, 1}]], MeshFunctions -> {#3&}, BoxRatios -> 1]In an even more extreme case, the level set can be the whole plane as
:
m = (| | |
| - | -- |
| 0 | -1 |
| 1 | 0 |);
PositiveSemidefiniteMatrixQ[m]{ContourPlot[q[x, y], {x, -2, 2}, {y, -2, 2}], Plot3D[q[x, y], {x, y}∈Rectangle[{-1, -1}, {1, 1}], MeshFunctions -> {#3&}, BoxRatios -> 1]}For a real, positive semidefinite
matrix, the level sets are
-ellipsoids:
m = (| | | |
| -- | -- | - |
| 3 | -1 | 0 |
| -1 | 3 | 0 |
| 0 | 0 | 3 |);PositiveSemidefiniteMatrixQ[m]ContourPlot3D[{x, y, z}.m.{x, y, z}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Contours -> {1, 4, 9}, ContourStyle -> Opacity[0.5], Mesh -> None]In three dimensions, these can degenerate into cylinders over ellipses:
m = (| | | |
| -- | -- | - |
| 3 | -1 | 0 |
| -1 | 3 | 0 |
| 0 | 0 | 0 |);
PositiveSemidefiniteMatrixQ[m]ContourPlot3D[{x, y, z}.m.{x, y, z}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Contours -> {1, 4, 9}, ContourStyle -> Opacity[0.5], Mesh -> None]m = (| | | |
| - | - | - |
| 1 | 1 | 0 |
| 1 | 1 | 0 |
| 0 | 0 | 0 |);
PositiveSemidefiniteMatrixQ[m]ContourPlot3D[{x, y, z}.m.{x, y, z}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, Contours -> {1, 4, 9}, ContourStyle -> Opacity[0.5], Mesh -> None]A Hermitian matrix defines a real-valued quadratic form by
:
m = (| | |
| ----- | ----- |
| 5 | 2 + I |
| 2 - I | 1 |);
q[w_, z_] := {w, z}.m.{w, z}
Reduce[q[w, z]∈Reals, {w, z}]If
is positive semidefinite,
is non-negative for all inputs:
Reduce[Subscript[∀, {w, z}]q[w, z] >= 0, {w, z}, Complexes]Visualize
for real-valued inputs:
Plot3D[q[x, y], {x, y}∈Disk[{0, 0}, 1], BoxRatios -> 1, Mesh -> None]For a real-valued matrix
, only the symmetric part determines whether
is positive semidefinite. Write
with
symmetric and
antisymmetric:
m = (| | |
| - | - |
| 1 | 2 |
| 3 | 4 |);
MatrixForm[s = (m + m/2)]MatrixForm[a = (m - m/2)]m == s + a && SymmetricMatrixQ[s] && AntisymmetricMatrixQ[a]As
is real and symmetric
, meaning
is purely real:
x = RandomComplex[1 + I, 2];
x.s.x//ChopSimilarly, as
is real and antisymmetric
, or
is pure imaginary:
x = RandomComplex[1 + I, 2];
x.a.x//ChopThus,
, so
is positive semidefinite if and only if
is:
{PositiveSemidefiniteMatrixQ[m], PositiveSemidefiniteMatrixQ[h]}For a complex-valued matrix
, only the Hermitian part determines whether
is positive semidefinite. Write
with
Hermitian and
antihermitian:
m = (| | |
| ------- | ------- |
| 1 + 5 I | 2 + 6 I |
| 3 + 7 I | 4 + 8I |);
MatrixForm[h = (m + m/2)]MatrixForm[a = (m - m/2)]m == h + a && HermitianMatrixQ[h] && AntihermitianMatrixQ[a]As
is Hermitian,
, meaning
is purely real:
x = RandomComplex[1 + I, 2];
x.h.x//ChopSimilarly, as
is antihermitian,
, or
is pure imaginary:
x = RandomComplex[1 + I, 2];
x.a.x//ChopThus,
, so
is positive semidefinite if and only if
is:
{PositiveSemidefiniteMatrixQ[m], PositiveSemidefiniteMatrixQ[s]}Sources of Positive Definite Matrices (8)
A real Covariance matrix is always symmetric and positive semidefinite:
Block[{Σ = Covariance[RandomReal[1, {5, 3}]]}, SymmetricMatrixQ[Σ] && PositiveSemidefiniteMatrixQ[Σ]]Block[{Σ = Covariance[RandomComplex[1 + I, {5, 3}]]}, HermitianMatrixQ[Σ] && PositiveSemidefiniteMatrixQ[Σ]]Compute SingularValueDecomposition[m] for a square matrix
:
{u, σ, v} = SingularValueDecomposition[RandomReal[1, {5, 5}]];The
matrix is positive semidefinite:
PositiveSemidefiniteMatrixQ[σ]A Gram matrix is a symmetric matrix of
dot products of
vectors:
n = 5;
v = RandomReal[1., {n, n}];
m = Table[v[[i]].v[[j]], {i, n}, {j, n}];A Gram matrix is always positive semidefinite:
PositiveSemidefiniteMatrixQ[m]Matrices drawn from WishartMatrixDistribution are real, symmetric and positive semidefinite:
(m |-> m∈Reals && SymmetricMatrixQ[m] && PositiveSemidefiniteMatrixQ[m]) /@ RandomVariate[WishartMatrixDistribution[5, {{1, 1 / 2, 0}, {1 / 2, 2, -1 / 2}, {0, -1 / 2, 1}}], {10}]The squares of Hermitian matrices are positive semidefinite:
m = RandomVariate[GaussianUnitaryMatrixDistribution[5]];HermitianMatrixQ[m]PositiveSemidefiniteMatrixQ[MatrixPower[m, 2]]Every antihermitian matrix is positive semidefinite:
m = I RandomVariate[GaussianUnitaryMatrixDistribution[5]];{AntihermitianMatrixQ[m], PositiveSemidefiniteMatrixQ[m]}The Lehmer matrix is symmetric positive semidefinite:
lehmer = Table[Min[i, j] / Max[i, j], {i, 5}, {j, 5}];
{SymmetricMatrixQ[lehmer], PositiveSemidefiniteMatrixQ[lehmer]}Its inverse is tridiagonal, which is also symmetric positive semidefinite:
inv = Inverse[lehmer]{SymmetricMatrixQ[inv], PositiveSemidefiniteMatrixQ[inv]}The matrix Min[i,j] is always symmetric positive semidefinite:
minij = Table[Min[i, j], {i, 5}, {j, 5}];
{SymmetricMatrixQ[minij], PositiveSemidefiniteMatrixQ[minij]}Its inverse is a tridiagonal matrix, which is also symmetric positive semidefinite:
inv = Inverse[minij]{SymmetricMatrixQ[inv], PositiveSemidefiniteMatrixQ[inv]}Properties & Relations (13)
PositiveSemidefiniteMatrixQ[x] trivially returns False for any x that is not a matrix:
PositiveSemidefiniteMatrixQ[Sqrt[3]]A matrix
is positive semidefinite if
for all vectors
:
m = {{1, 2I}, {-I, 4}};
PositiveSemidefiniteMatrixQ[m]Reduce[Subscript[∀, {Subscript[x, 1], Subscript[x, 2]}]Re[{Subscript[x, 1], Subscript[x, 2]}.m.{Subscript[x, 1], Subscript[x, 2]}] >= 0, {Subscript[x, 1], Subscript[x, 2]}, Complexes]Block[{x = {1, 1 - I}}, Im[x.m.x]]Block[{x = {1, -1 - I}}, Im[x.m.x]]A real matrix
is positive semidefinite if and only if its symmetric part is positive semidefinite:
m = (| | |
| -- | - |
| 6 | 4 |
| -2 | 8 |);s = Symmetrize[m];{PositiveSemidefiniteMatrixQ[m], PositiveSemidefiniteMatrixQ[s]}In general, a matrix
is positive semidefinite if and only if its Hermitian part is positive semidefinite:
c = (| | |
| --- | ------ |
| 4 | 4 I |
| -2I | 4 + 2I |);h = Symmetrize[c, Hermitian[All]];{PositiveSemidefiniteMatrixQ[c], PositiveSemidefiniteMatrixQ[h]}A real symmetric matrix is positive semidefinite if and only if its eigenvalues are all non-negative:
s = (| | |
| - | - |
| 2 | 1 |
| 1 | 2 |);SymmetricMatrixQ[s] && PositiveSemidefiniteMatrixQ[s]And @@NonNegative /@ Eigenvalues[s]The statement is true of Hermitian matrices more generally:
h = (| | |
| --------- | -------- |
| 1 | ISqrt[2] |
| -ISqrt[2] | 2 |);{HermitianMatrixQ[h] && PositiveSemidefiniteMatrixQ[h], And@@NonNegative /@ Eigenvalues[h]}A general matrix can have all non-negative eigenvalues without being positive semidefinite:
NonNegative /@ Eigenvalues[(| | |
| - | -- |
| 4 | -1 |
| 2 | 0 |)]PositiveSemidefiniteMatrixQ[(| | |
| - | -- |
| 4 | -1 |
| 2 | 0 |)]Equally, a matrix can be positive semidefinite without having non-negative eigenvalues:
PositiveSemidefiniteMatrixQ[(| | |
| -- | - |
| 6 | 4 |
| -2 | 8 |)]λ = Eigenvalues[(| | |
| -- | - |
| 6 | 4 |
| -2 | 8 |)];
NonNegative /@ λThe failure is due to the eigenvalues being complex:
λThe real part of the eigenvalues of a positive semidefinite matrix must be non-negative:
NonNegative /@ Re[λ]A diagonal matrix is positive semidefinite if and only if diagonal elements have non-negative real parts:
PositiveSemidefiniteMatrixQ[(| | | |
| - | - | -- |
| 1 | 0 | 0 |
| 0 | 2 | 0 |
| 0 | 0 | -1 |)]PositiveSemidefiniteMatrixQ[(| | | |
| - | - | - |
| 1 | 0 | 0 |
| 0 | 2 | 0 |
| 0 | 0 | 0 |)]A positive semidefinite matrix has the general form
with a diagonal positive semidefinite
:
m = (| | | |
| ----------------------------------------- | ------------------------------------------ | ------------------------------------------ |
| 3.792168950417362 | 2.973638210582098 + 1.4338467608374894 I | 2.6847137114282464 + 1.096732668646098 I |
| 2.5943303334981036 - 1.4338467608374894 I | 3.722968070528689 | 2.2427900539994767 + 0.15267916356932992 I |
| 2.3008034014752843 - 1.096732668646098 I | 2.5698503388043816 - 0.15267916356933003 I | 3.1 + I |);
PositiveSemidefiniteMatrixQ[m]Split
into its Hermitian and antihermitian parts:
h = Symmetrize[m, Hermitian[All]];a = Symmetrize[m, Antihermitian[All]];By the spectral theorem,
can be unitarily diagonalized using JordanDecomposition:
{u, d} = JordanDecomposition[h];The matrix
is diagonal with non-negative diagonal entries:
d//MatrixFormUnitaryMatrixQ[u]u.d.u + a - m//ChopA matrix
is positive semidefinite if and only if
is negative semidefinite:
m = (| | | | |
| ------------------------------------------- | ------------------------------------------- | ------------------------------------------- | ------------------------------------------- |
| 0.8368175179836128 + 0. I | 0.08442148190943044 - 0.07261632146865446 I | -1.2128453065519185 + 0.2791488701895241 I | -0.7176461452206016 + 0.09729452115881893 I |
| 0.08442148190943044 + 0.07261632146865446 I | 3.39669580879013 + 0. I | -0.11306601611673339 - 1.0251509468914757 I | -1.3902042643674577 + 0.8867050522199316 I |
| -1.2128453065519185 - 0.2791488701895241 I | -0.11306601611673339 + 1.0251509468914757 I | 4.960363408128666 + 0. I | 0.3541172390806834 + 0.5132293867878579 I |
| -0.7176461452206016 - 0.09729452115881893 I | -1.3902042643674577 - 0.8867050522199316 I | 0.3541172390806834 - 0.5132293867878579 I | 1.6764327323058408 + 0. I |);{PositiveSemidefiniteMatrixQ[m], NegativeDefiniteMatrixQ[-m]}A positive definite matrix is always positive semidefinite:
m = {{3, -1}, {1, 2}};{PositiveDefiniteMatrixQ[m], PositiveSemidefiniteMatrixQ[m]}There are positive semidefinite matrices that are not positive definite:
s = {{3, Sqrt[6]}, {Sqrt[6], 2}};{PositiveDefiniteMatrixQ[s], PositiveSemidefiniteMatrixQ[s]}A positive semidefinite matrix cannot be indefinite or negative semidefinite:
{IndefiniteMatrixQ[s], NegativeSemidefiniteMatrixQ[s]}The determinant and trace of a real, symmetric, positive semidefinite matrix are non-negative:
s = MatrixPower[RandomVariate[GaussianOrthogonalMatrixDistribution[5]], 2];s∈Reals && SymmetricMatrixQ[s] && PositiveSemidefiniteMatrixQ[s]{Det[s] >= 0, Tr[s] >= 0}This is also true of positive semidefinite Hermitian matrices:
h = MatrixPower[RandomVariate[GaussianUnitaryMatrixDistribution[5]], 2];HermitianMatrixQ[h] && PositiveSemidefiniteMatrixQ[h]{Chop[Det[h]] >= 0, Tr[h] >= 0}A real symmetric positive semidefinite matrix
has a uniquely defined square root
such that
:
m = {{3.190023505153258, 2.4571124732137526, 3.1702589583416105}, {2.4571124732137526, 3.7756789190375084, 4.005717103481039}, {3.1702589583416105, 4.005717103481039, 4.806632993087039}};PositiveSemidefiniteMatrixQ[m] && SymmetricMatrixQ[m]b = MatrixFunction[Sqrt, m]m == b.bThe square root
is positive semidefinite and real symmetric:
{PositiveSemidefiniteMatrixQ[b], b∈Reals && SymmetricMatrixQ[b]}A Hermitian positive semidefinite matrix
has a uniquely defined square root
such that
:
m = {{4.4063915815780526, 2.415609335653971 - 0.9784858036636759 * I, 3.272554434576208 - 0.9581109282797712 * I}, {2.415609335653971 + 0.9784858036636759 * I, 3.2093833346047265, 2.1186156336423365 + 0.44745371013921886 * I}, {3.272554434576208 + 0.9581109282797711 * I, 2.1186156336423365 - 0.4474537101392189 * I, 2.711962460046668}};PositiveSemidefiniteMatrixQ[m] && HermitianMatrixQ[m]b = MatrixFunction[Sqrt, m]//Chopm - b.b//ChopThe square root
is positive semidefinite and Hermitian:
{PositiveSemidefiniteMatrixQ[b], HermitianMatrixQ[b]}The Kronecker product of two symmetric positive semidefinite matrices is symmetric and positive semidefinite:
m = {{1.7598185930089938, 0.7515334357458681, 2.2897627173188955}, {0.7515334357458681, 0.620015086572864, 0.7720746373602607}, {2.289762717318896, 0.7720746373602608, 3.12087091744294}};
n = {{0.10696857615478556, 0.09420715976163785}, {0.09420715976163785, 0.17814922498702113}};PositiveSemidefiniteMatrixQ[#] && SymmetricMatrixQ[#]& /@ {m, n}With[{prod = KroneckerProduct[m, n]}, {PositiveSemidefiniteMatrixQ[prod], SymmetricMatrixQ[prod]}]Replacing one matrix in the product by a negative semidefinite one gives a negative semidefinite matrix:
NegativeDefiniteMatrixQ[-n] && SymmetricMatrixQ[-n]With[{prod = KroneckerProduct[m, -n]},
NegativeSemidefiniteMatrixQ[prod] && SymmetricMatrixQ[prod]]Possible Issues (2)
CholeskyDecomposition does not work with symmetric or Hermitian positive semidefinite matrices that are singular:
m = DiagonalMatrix[{2., 1., 0.}];
PositiveSemidefiniteMatrixQ[m]CholeskyDecomposition[m]PositiveSemidefiniteMatrixQ gives False unless it can prove a symbolic matrix is positive semidefinite:
PositiveSemidefiniteMatrixQ[{{a Conjugate[a], 0}, {0, a Conjugate[a]}}]Using a combination of Eigenvalues and Reduce can give more precise results:
Eigenvalues[{{a Conjugate[a], 0}, {0, a Conjugate[a]}}]Reduce[Re[%]0, a, Complexes]Related Guides
History
Text
Wolfram Research (2014), PositiveSemidefiniteMatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html.
CMS
Wolfram Language. 2014. "PositiveSemidefiniteMatrixQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html.
APA
Wolfram Language. (2014). PositiveSemidefiniteMatrixQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html
BibTeX
@misc{reference.wolfram_2026_positivesemidefinitematrixq, author="Wolfram Research", title="{PositiveSemidefiniteMatrixQ}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_positivesemidefinitematrixq, organization={Wolfram Research}, title={PositiveSemidefiniteMatrixQ}, year={2014}, url={https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html}, note=[Accessed: 13-June-2026]}