WOLFRAM

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 allclose all

Basic Examples  (2)Summary of the most common use cases

Test if a 2×2 real matrix is explicitly positive semidefinite:

Out[2]=2

This means that the quadratic form for all vectors :

Out[3]=3

Visualize the values of the quadratic form:

Out[4]=4

Test if a 3×3 Hermitian matrix is positive semidefinite:

Out[1]=1

Scope  (10)Survey of the scope of standard use cases

Basic Uses  (6)

Test if a real machine-precision matrix is explicitly positive semidefinite:

Out[1]=1

Test if a complex matrix is positive semidefinite:

Out[1]=1

Test if an exact matrix is positive semidefinite:

Out[1]=1

Use PositiveSemidefiniteMatrixQ with an arbitrary-precision matrix:

Out[1]=1

A random matrix is typically not positive semidefinite:

Out[2]=2

Use PositiveSemidefiniteMatrixQ with a symbolic matrix:

Out[1]=1

The matrix becomes positive semidefinite when b=-TemplateBox[{a}, Conjugate]:

Out[2]=2

PositiveSemidefiniteMatrixQ works efficiently with large numerical matrices:

Out[2]=2
Out[3]=3

Special Matrices  (4)

Use PositiveSemidefiniteMatrixQ with sparse matrices:

Out[1]=1
Out[2]=2

Use PositiveSemidefiniteMatrixQ with structured matrices:

Out[1]=1
Out[2]=2

The identity matrix is positive semidefinite:

Out[1]=1

HilbertMatrix is positive semidefinite:

Out[1]=1

Options  (1)Common values & functionality for each option

Tolerance  (1)

Generate a real-valued diagonal matrix with some random perturbation of order 10-12:

Out[1]=1
Out[2]=2

Adjust the option Tolerance to accept matrices as positive semidefinite:

Out[3]=3

Applications  (13)Sample problems that can be solved with this function

The Geometry and Algebra of Positive Semidefinite Matrices  (5)

Consider a real, positive semidefinite 2×2 matrix and its associated real quadratic q=TemplateBox[{x}, Transpose].m.x:

Out[2]=2

Because is positive definite, the level sets are ellipses:

Out[4]=4

The plot of will be an upward-facing elliptic paraboloid:

Out[5]=5

However, the ellipses can be degenerate, turning into lines:

Out[6]=6
Out[7]=7

The plot of is then a cylinder over a parabola:

Out[9]=9

In an even more extreme case, the level set can be the whole plane as :

Out[9]=9
Out[10]=10

For a real, positive semidefinite matrix, the level sets are -ellipsoids:

Out[2]=2
Out[3]=3

In three dimensions, these can degenerate into cylinders over ellipses:

Out[4]=4
Out[5]=5

As well as planes:

Out[6]=6
Out[7]=7

A Hermitian matrix defines a real-valued quadratic form by q=TemplateBox[{x}, ConjugateTranspose].m.x:

Out[1]=1

If is positive semidefinite, is non-negative for all inputs:

Out[2]=2

Visualize for real-valued inputs:

Out[3]=3

For a real-valued matrix , only the symmetric part determines whether is positive semidefinite. Write with symmetric and antisymmetric:

Out[3]=3

As is real and symmetric TemplateBox[{{(, {TemplateBox[{x}, ConjugateTranspose, SyntaxForm -> SuperscriptBox], ., s, ., x}, )}}, Conjugate]=TemplateBox[{{(, {TemplateBox[{x}, ConjugateTranspose, SyntaxForm -> SuperscriptBox], ., s, ., x}, )}}, ConjugateTranspose]=TemplateBox[{x}, ConjugateTranspose].TemplateBox[{s}, ConjugateTranspose].TemplateBox[{{(, TemplateBox[{x}, ConjugateTranspose, SyntaxForm -> SuperscriptBox], )}}, ConjugateTranspose]=TemplateBox[{x}, ConjugateTranspose].s.x, meaning TemplateBox[{x}, ConjugateTranspose].s.x is purely real:

Out[4]=4

Similarly, as is real and antisymmetric TemplateBox[{{(, {TemplateBox[{x}, ConjugateTranspose, SyntaxForm -> SuperscriptBox], ., a, ., x}, )}}, Conjugate]=-TemplateBox[{x}, ConjugateTranspose].a.x, or TemplateBox[{x}, ConjugateTranspose].a.x is pure imaginary:

Out[5]=5

Thus, Re(TemplateBox[{x}, ConjugateTranspose].m.x)=TemplateBox[{x}, ConjugateTranspose].s.x, so is positive semidefinite if and only if is:

Out[6]=6

For a complex-valued matrix , only the Hermitian part determines whether is positive semidefinite. Write with Hermitian and antihermitian:

Out[3]=3

As is Hermitian, TemplateBox[{{(, {TemplateBox[{x}, ConjugateTranspose], ., h, ., x}, )}}, Conjugate]=TemplateBox[{{(, {TemplateBox[{x}, ConjugateTranspose], ., h, ., x}, )}}, ConjugateTranspose]=TemplateBox[{x}, ConjugateTranspose].TemplateBox[{h}, ConjugateTranspose].TemplateBox[{{(, TemplateBox[{x}, ConjugateTranspose, SyntaxForm -> SuperscriptBox], )}}, ConjugateTranspose]=TemplateBox[{x}, ConjugateTranspose].h.x, meaning TemplateBox[{x}, ConjugateTranspose].h.x is purely real:

Out[4]=4

Similarly, as is antihermitian, TemplateBox[{{(, {TemplateBox[{x}, ConjugateTranspose, SyntaxForm -> SuperscriptBox], ., a, ., x}, )}}, Conjugate]=-TemplateBox[{x}, ConjugateTranspose].a.x, or TemplateBox[{x}, ConjugateTranspose].a.x is pure imaginary:

Out[5]=5

Thus, Re(TemplateBox[{x}, ConjugateTranspose].m.x)=TemplateBox[{x}, ConjugateTranspose].h.x, so is positive semidefinite if and only if is:

Out[6]=6

Sources of Positive Definite Matrices  (8)

A real Covariance matrix is always symmetric and positive semidefinite:

Out[1]=1

A complex one is Hermitian:

Out[2]=2

Compute SingularValueDecomposition[m] for a square matrix :

The matrix is positive semidefinite:

Out[2]=2

A Gram matrix is a symmetric matrix of dot products of vectors:

A Gram matrix is always positive semidefinite:

Out[2]=2

Matrices drawn from WishartMatrixDistribution are real, symmetric and positive semidefinite:

Out[1]=1

The squares of Hermitian matrices are positive semidefinite:

Out[2]=2
Out[3]=3

Every antihermitian matrix is positive semidefinite:

Out[2]=2

The Lehmer matrix is symmetric positive semidefinite:

Out[1]=1

Its inverse is tridiagonal, which is also symmetric positive semidefinite:

Out[2]=2
Out[3]=3

The matrix Min[i,j] is always symmetric positive semidefinite:

Out[1]=1

Its inverse is a tridiagonal matrix, which is also symmetric positive semidefinite:

Out[2]=2
Out[3]=3

Properties & Relations  (13)Properties of the function, and connections to other functions

PositiveSemidefiniteMatrixQ[x] trivially returns False for any x that is not a matrix:

Out[1]=1

A matrix is positive semidefinite if Re(TemplateBox[{x}, ConjugateTranspose].m.x)>=0 for all vectors :

Out[1]=1
Out[2]=2

The sign of Im(TemplateBox[{x}, ConjugateTranspose].m.x) is irrelevant:

Out[3]=3
Out[4]=4

A real matrix is positive semidefinite if and only if its symmetric part is positive semidefinite:

Out[2]=2

In general, a matrix is positive semidefinite if and only if its Hermitian part is positive semidefinite:

Out[4]=4

A real symmetric matrix is positive semidefinite if and only if its eigenvalues are all non-negative:

Out[2]=2
Out[3]=3

The statement is true of Hermitian matrices more generally:

Out[5]=5

A general matrix can have all non-negative eigenvalues without being positive semidefinite:

Out[1]=1
Out[2]=2

Equally, a matrix can be positive semidefinite without having non-negative eigenvalues:

Out[3]=3
Out[4]=4

The failure is due to the eigenvalues being complex:

Out[5]=5

The real part of the eigenvalues of a positive semidefinite matrix must be non-negative:

Out[6]=6

A diagonal matrix is positive semidefinite if and only if diagonal elements have non-negative real parts:

Out[1]=1
Out[2]=2

A positive semidefinite matrix has the general form u.d.TemplateBox[{u}, ConjugateTranspose]+a with a diagonal positive semidefinite :

Out[1]=1

Split into its Hermitian and antihermitian parts:

By the spectral theorem, can be unitarily diagonalized using JordanDecomposition:

The matrix is diagonal with non-negative diagonal entries:

The matrix is unitary:

Out[6]=6

Verify that m=u.d.TemplateBox[{u}, ConjugateTranspose]+a:

Out[7]=7

A matrix is positive semidefinite if and only if is negative semidefinite:

Out[2]=2

A positive definite matrix is always positive semidefinite:

Out[2]=2

There are positive semidefinite matrices that are not positive definite:

Out[4]=4

A positive semidefinite matrix cannot be indefinite or negative semidefinite:

Out[5]=5

The determinant and trace of a real, symmetric, positive semidefinite matrix are non-negative:

Out[2]=2
Out[3]=3

This is also true of positive semidefinite Hermitian matrices:

Out[5]=5
Out[6]=6

A real symmetric positive semidefinite matrix has a uniquely defined square root such that :

Out[2]=2
Out[3]=3
Out[4]=4

The square root is positive semidefinite and real symmetric:

Out[5]=5

A Hermitian positive semidefinite matrix has a uniquely defined square root such that :

Out[2]=2
Out[3]=3
Out[4]=4

The square root is positive semidefinite and Hermitian:

Out[5]=5

The Kronecker product of two symmetric positive semidefinite matrices is symmetric and positive semidefinite:

Out[2]=2
Out[3]=3

Replacing one matrix in the product by a negative semidefinite one gives a negative semidefinite matrix:

Out[4]=4
Out[5]=5

Possible Issues  (2)Common pitfalls and unexpected behavior

CholeskyDecomposition does not work with symmetric or Hermitian positive semidefinite matrices that are singular:

Out[2]=2
Out[3]=3

PositiveSemidefiniteMatrixQ gives False unless it can prove a symbolic matrix is positive semidefinite:

Out[1]=1

Using a combination of Eigenvalues and Reduce can give more precise results:

Out[2]=2
Out[3]=3
Wolfram Research (2014), PositiveSemidefiniteMatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html.
Wolfram Research (2014), PositiveSemidefiniteMatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html.

Text

Wolfram Research (2014), PositiveSemidefiniteMatrixQ, Wolfram Language function, https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html.

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.

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

Wolfram Language. (2014). PositiveSemidefiniteMatrixQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html

BibTeX

@misc{reference.wolfram_2025_positivesemidefinitematrixq, author="Wolfram Research", title="{PositiveSemidefiniteMatrixQ}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html}", note=[Accessed: 26-March-2025 ]}

@misc{reference.wolfram_2025_positivesemidefinitematrixq, author="Wolfram Research", title="{PositiveSemidefiniteMatrixQ}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html}", note=[Accessed: 26-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_positivesemidefinitematrixq, organization={Wolfram Research}, title={PositiveSemidefiniteMatrixQ}, year={2014}, url={https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html}, note=[Accessed: 26-March-2025 ]}

@online{reference.wolfram_2025_positivesemidefinitematrixq, organization={Wolfram Research}, title={PositiveSemidefiniteMatrixQ}, year={2014}, url={https://reference.wolfram.com/language/ref/PositiveSemidefiniteMatrixQ.html}, note=[Accessed: 26-March-2025 ]}