NegativeSemidefiniteMatrixQ[m]
gives True if m is explicitly negative semidefinite, and False otherwise.
NegativeSemidefiniteMatrixQ
NegativeSemidefiniteMatrixQ[m]
gives True if m is explicitly negative semidefinite, and False otherwise.
Details and Options
- A matrix m is negative semidefinite if Re[Conjugate[x].m.x]≤0 for all vectors x. »
- NegativeSemidefiniteMatrixQ 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 negative semidefinite:
m = {{-2, 0}, {0, 0}};NegativeSemidefiniteMatrixQ[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 negative semidefinite:
NegativeSemidefiniteMatrixQ[(| | | |
| ---------------- | -------------- | ---------------- |
| -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 negative semidefinite:
NegativeSemidefiniteMatrixQ[{{-1.6, 0.8}, {0.8, -0.4}}]Test if a complex matrix is negative semidefinite:
NegativeSemidefiniteMatrixQ[{{-1, -2 I}, {I, -3}}]Test if an exact matrix is negative semidefinite:
NegativeSemidefiniteMatrixQ[(| | | |
| - | ------- | -- |
| π | -5 | 2 |
| E | -3 | -3 |
| 5 | Sqrt[2] | 5 |)]Use NegativeSemidefiniteMatrixQ with an arbitrary-precision matrix:
m = RandomReal[5, {3, 3}, WorkingPrecision -> 15]A random matrix is typically not negative semidefinite:
NegativeSemidefiniteMatrixQ[m]Use NegativeSemidefiniteMatrixQ with a symbolic matrix:
NegativeSemidefiniteMatrixQ[{{0, a}, {b, 0}}]The matrix becomes negative semidefinite when
:
Block[{b = -Conjugate[a]}, NegativeSemidefiniteMatrixQ[{{0, a}, {b, 0}}]]NegativeSemidefiniteMatrixQ works efficiently with large numerical matrices:
m = RandomReal[1, {1000, 1000}];AbsoluteTiming[NegativeSemidefiniteMatrixQ[m]]a = -m.m^;
AbsoluteTiming[NegativeSemidefiniteMatrixQ[a]]Special Matrices (4)
Use NegativeSemidefiniteMatrixQ with sparse matrices:
SparseArray[{{i_, i_} -> -2., {i_, j_} /; Abs[i - j] == 1 -> -1.}, {10, 10}, 0.]NegativeSemidefiniteMatrixQ[%]Use NegativeSemidefiniteMatrixQ with structured matrices:
SymmetrizedArray[{{1, 1} -> -5, {1, 2} -> -11, {2, 2} -> -25}, {2, 2}, Symmetric[All]]NegativeSemidefiniteMatrixQ[%]The identity matrix is not negative semidefinite:
NegativeSemidefiniteMatrixQ[IdentityMatrix[5]]HilbertMatrix is not negative semidefinite:
NegativeSemidefiniteMatrixQ[HilbertMatrix[5]]Options (1)
Tolerance (1)
Generate a real-valued diagonal matrix with some random perturbation of order
:
SeedRandom[56];
m = {{-2, 0, 0}, {0, -1, 0}, {0, 0, 0}} + 10 ^ -13 * DiagonalMatrix[RandomReal[{1, 10}, 3]]NegativeSemidefiniteMatrixQ[m]Adjust the option Tolerance to accept matrices as negative semidefinite:
NegativeSemidefiniteMatrixQ[m, Tolerance -> 10 ^ -12]Applications (10)
The Geometry and Algebra of Negative Semidefinite Matrices (5)
Consider a real, negative semidefinite 2×2 matrix and its associated real quadratic
:
m = (| | |
| -- | -- |
| -3 | 1 |
| 1 | -3 |);
NegativeSemidefiniteMatrixQ[m]q[x_, y_] := {x, y}.m.{x, y}Because
is negative definite, the level sets are ellipses:
ContourPlot[q[x, y], {x, -2, 2}, {y, -2, 2}]The plot of
will be an downward-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 |);
NegativeSemidefiniteMatrixQ[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 |);
NegativeSemidefiniteMatrixQ[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, negative semidefinite
matrix, the level sets are
-ellipsoids:
m = (| | | |
| -- | -- | -- |
| -3 | 1 | 0 |
| 1 | -3 | 0 |
| 0 | 0 | -3 |);NegativeSemidefiniteMatrixQ[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 |);
NegativeSemidefiniteMatrixQ[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 |);
NegativeSemidefiniteMatrixQ[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 negative semidefinite,
is non-positive 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 negative 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 negative semidefinite if and only if
is:
{NegativeSemidefiniteMatrixQ[m], NegativeSemidefiniteMatrixQ[h]}For a complex-valued matrix
, only the Hermitian part determines whether
is negative 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 negative semidefinite if and only if
is:
{NegativeSemidefiniteMatrixQ[m], NegativeSemidefiniteMatrixQ[s]}Sources of Negative Semidefinite Matrices (5)
Two-dimensional rotation matrices with angles in the interval
are negative semidefinite:
θ = RandomReal[{π / 2, 3π / 2}, {10}];
r = RotationMatrix /@ θ;
NegativeSemidefiniteMatrixQ /@ rThis follows from the fact that in this case
corresponds to the normal dot product and
:
Re[{x, y}.r[[1]].{x, y}] == Norm[{x, y}]^2Cos[θ[[1]]]//FullSimplifyThus, for
, the matrices are in fact negative definite:
NegativeDefiniteMatrixQ /@ rAt the endpoints they are negative semidefinite but not negative definite:
{NegativeSemidefiniteMatrixQ[RotationMatrix[π / 2]], NegativeDefiniteMatrixQ[RotationMatrix[π / 2]]}The squares of antihermitian matrices are negative definite:
m = I RandomVariate[GaussianUnitaryMatrixDistribution[5]];AntihermitianMatrixQ[m]NegativeSemidefiniteMatrixQ[MatrixPower[m, 2]]Every antihermitian matrix is negative semidefinite:
m = I RandomVariate[GaussianUnitaryMatrixDistribution[5]];{AntihermitianMatrixQ[m], NegativeSemidefiniteMatrixQ[m]}The negated Lehmer matrix is symmetric negative semidefinite:
nlehmer = Table[-Min[i, j] / Max[i, j], {i, 5}, {j, 5}];
{SymmetricMatrixQ[nlehmer], NegativeSemidefiniteMatrixQ[nlehmer]}Its inverse is tridiagonal, which is also symmetric negative definite:
inv = Inverse[nlehmer]{SymmetricMatrixQ[inv], NegativeSemidefiniteMatrixQ[inv]}The matrix -Min[i,j] is always symmetric negative semidefinite:
nminij = Table[-Min[i, j], {i, 5}, {j, 5}];
{SymmetricMatrixQ[nminij], NegativeSemidefiniteMatrixQ[nminij]}Its inverse is a tridiagonal matrix, which is also symmetric negative definite:
inv = Inverse[nminij]{SymmetricMatrixQ[inv], NegativeSemidefiniteMatrixQ[inv]}Properties & Relations (13)
NegativeSemidefiniteMatrixQ[x] trivially returns False for any x that is not a matrix:
NegativeSemidefiniteMatrixQ[Sqrt[3]]A matrix
is negative semidefinite if
for all vectors
:
m = {{-1, 2I}, {-I, -4}};
NegativeSemidefiniteMatrixQ[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 negative semidefinite if and only if its symmetric part is negative semidefinite:
m = (| | |
| -- | -- |
| -6 | 4 |
| -2 | -8 |);s = Symmetrize[m];{NegativeSemidefiniteMatrixQ[m], NegativeSemidefiniteMatrixQ[s]}In general, a matrix
is negative semidefinite if and only if its Hermitian part is negative semidefinite:
c = (| | |
| --- | ------- |
| -4 | 4 I |
| -2I | -4 + 2I |);h = Symmetrize[c, Hermitian[All]];{NegativeSemidefiniteMatrixQ[c], NegativeSemidefiniteMatrixQ[h]}A real symmetric matrix is negative semidefinite if and only if its eigenvalues are all non-positive:
s = (| | |
| -- | -- |
| -2 | -1 |
| -1 | -2 |);SymmetricMatrixQ[s] && NegativeSemidefiniteMatrixQ[s]And @@NonPositive /@ Eigenvalues[s]The statement is true of Hermitian matrices more generally:
h = (| | |
| --------- | -------- |
| -1 | ISqrt[2] |
| -ISqrt[2] | -2 |);{HermitianMatrixQ[h] && NegativeSemidefiniteMatrixQ[h], And@@NonPositive /@ Eigenvalues[h]}A general matrix can have all non-positive eigenvalues without being negative semidefinite:
NonPositive /@ Eigenvalues[(| | |
| -- | -- |
| -4 | -1 |
| 2 | 0 |)]NegativeSemidefiniteMatrixQ[(| | |
| -- | -- |
| -4 | -1 |
| 2 | 0 |)]Equally, a matrix can be negative semidefinite without having non-positive eigenvalues:
NegativeSemidefiniteMatrixQ[(| | |
| -- | -- |
| -6 | -4 |
| 2 | -8 |)]λ = Eigenvalues[(| | |
| -- | -- |
| -6 | -4 |
| 2 | -8 |)];
NonPositive /@ λThe failure is due to the eigenvalues being complex:
λThe real part of the eigenvalues of a negative semidefinite matrix must be non-positive:
NonPositive /@ Re[λ]A diagonal matrix is negative semidefinite if and only if diagonal elements have non-positive real parts:
NegativeSemidefiniteMatrixQ[(| | | |
| -- | -- | - |
| -1 | 0 | 0 |
| 0 | -2 | 0 |
| 0 | 0 | 1 |)]NegativeSemidefiniteMatrixQ[(| | | |
| -- | -- | - |
| -1 | 0 | 0 |
| 0 | -2 | 0 |
| 0 | 0 | 0 |)]A negative semidefinite matrix has the general form
with a diagonal negative 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 |);
NegativeSemidefiniteMatrixQ[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-positive diagonal entries:
d//MatrixFormUnitaryMatrixQ[u]u.d.u + a - m//ChopA matrix
is negative semidefinite if and only if
is positive 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 |);{NegativeSemidefiniteMatrixQ[m], PositiveDefiniteMatrixQ[-m]}A negative definite matrix is always negative semidefinite:
m = {{-3, 1}, {-1, -2}};{NegativeDefiniteMatrixQ[m], NegativeSemidefiniteMatrixQ[m]}There are negative semidefinite matrices that are not negative definite:
s = {{-3, -Sqrt[6]}, {-Sqrt[6], -2}};{NegativeDefiniteMatrixQ[s], NegativeSemidefiniteMatrixQ[s]}A negative semidefinite matrix cannot be indefinite or positive semidefinite:
{IndefiniteMatrixQ[s], PositiveSemidefiniteMatrixQ[s]}The determinant and trace of a real, symmetric, negative semidefinite matrix are non-positive:
s = -MatrixPower[RandomVariate[GaussianOrthogonalMatrixDistribution[5]], 2];s∈Reals && SymmetricMatrixQ[s] && NegativeSemidefiniteMatrixQ[s]{Det[s] <= 0, Tr[s] <= 0}This is also true of negative semidefinite Hermitian matrices:
h = -MatrixPower[RandomVariate[GaussianUnitaryMatrixDistribution[5]], 2];HermitianMatrixQ[h] && NegativeSemidefiniteMatrixQ[h]{Chop[Det[h]] <= 0, Tr[h] <= 0}A real symmetric negative 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}};NegativeSemidefiniteMatrixQ[m] && SymmetricMatrixQ[m]b = MatrixFunction[Sqrt, m]m == b.bThe root is uniquely defined by the condition that
is negative semidefinite and Hermitian:
NegativeSemidefiniteMatrixQ[I b] && HermitianMatrixQ[I b]A Hermitian negative 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}};NegativeSemidefiniteMatrixQ[m] && HermitianMatrixQ[m]b = MatrixFunction[Sqrt, m]//Chopm - b.b//ChopThe root is uniquely defined by the condition that
is negative semidefinite and Hermitian:
{NegativeSemidefiniteMatrixQ[I b], HermitianMatrixQ[I b]}The Kronecker product of two symmetric negative 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}};NegativeSemidefiniteMatrixQ[#] && 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:
PositiveSemidefiniteMatrixQ[-n] && SymmetricMatrixQ[-n]With[{prod = KroneckerProduct[m, -n]},
NegativeSemidefiniteMatrixQ[prod] && SymmetricMatrixQ[prod]]Possible Issues (1)
NegativeSemidefiniteMatrixQ gives False unless it can prove a symbolic matrix is positive semidefinite:
NegativeSemidefiniteMatrixQ[{{-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), NegativeSemidefiniteMatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/NegativeSemidefiniteMatrixQ.html.
CMS
Wolfram Language. 2014. "NegativeSemidefiniteMatrixQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NegativeSemidefiniteMatrixQ.html.
APA
Wolfram Language. (2014). NegativeSemidefiniteMatrixQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NegativeSemidefiniteMatrixQ.html
BibTeX
@misc{reference.wolfram_2026_negativesemidefinitematrixq, author="Wolfram Research", title="{NegativeSemidefiniteMatrixQ}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/NegativeSemidefiniteMatrixQ.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_negativesemidefinitematrixq, organization={Wolfram Research}, title={NegativeSemidefiniteMatrixQ}, year={2014}, url={https://reference.wolfram.com/language/ref/NegativeSemidefiniteMatrixQ.html}, note=[Accessed: 12-June-2026]}