IsPSD

IsPSD is a function that determines whether or not a given matrix is positive semidefinite. The input matrix can be either full or sparse and, if requested, a vector that proves that the given matrix is not positive semidefinite can be provided as output.

Syntax

 * PSD = IsPSD(X)
 * PSD = IsPSD(X,TOL)
 * [PSD,WIT] = IsPSD(X,TOL)

Input arguments

 * X: A square matrix.
 * TOL (optional, default eps^(3/4)): The numerical tolerance used when determining positive semidefiniteness. The matrix will be determined to be positive semidefinite if its minimal eigenvalue is computed to be at least -TOL.

Output arguments

 * PSD</tt>: A flag (either 1 or 0) indicating that X</tt> is or is not positive semidefinite.
 * WIT</tt> (optional): An eigenvector corresponding to the minimal eigenvalue of X</tt>. When PSD = 0</tt>, this serves as a witness that verifies that X</tt> is not positive semidefinite, since WIT'*X*WIT < 0</tt>.

Simple example with low tolerance
When X</tt> is very simple, positive semidefiniteness can be be determined exactly. The following example has the TOL = 0</tt> (not recommended in general!) to highlight the fact that the script really is checking for positive semidefiniteness, not positive definiteness.

Furthermore, if we make one of the eigenvalues even slightly negative in this case, it is detected as not positive semidefinite:

Note that in general you can not expect this kind of accuracy.