Check whether a symmetric matrix is positive or negative semidefinite.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ```
isSemidefinite( m, ... )
## Default S3 method:
isSemidefinite( m, ... )
## S3 method for class 'matrix'
isSemidefinite( m, positive = TRUE,
tol = 100 * .Machine$double.eps,
method = ifelse( nrow( m ) < 13, "det", "eigen" ), ... )
## S3 method for class 'list'
isSemidefinite( m, ... )
semidefiniteness( m, ... )
``` |

`m` |
a symmetric quadratic matrix or a list containing symmetric quadratic matrices. |

`positive` |
logical. Check for positive semidefiniteness
(if |

`tol` |
tolerance level (values between |

`method` |
method to test for semidefiniteness, either
checking the signs of the principal minors
(if |

`...` |
further arguments of |

Function `semidefiniteness()`

passes all its arguments
to `isSemidefinite()`

.
It is only kept for backward-compatibility
and may be removed in the future.

If argument `positive`

is set to `FALSE`

,
`isSemidefinite()`

checks for negative semidefiniteness
by checking for positive semidefiniteness
of the negative of argument `m`

, i.e. `-m`

.

If method `"det"`

is used
(default for matrices with up to 12 rows/columns),
`isSemidefinite()`

checks whether all principal minors
(not only the leading principal minors)
of the matrix `m`

(or of the matrix `-m`

if argument `positive`

is `FALSE`

)
are larger than `-tol`

.
Due to rounding errors,
which are unavoidable on digital computers,
the calculated determinants of singular (sub-)matrices
(which should theoretically be zero)
can considerably deviate from zero.
In order to reduce the probability of incorrect results
due to rounding errors,
`isSemidefinite()`

does not calculate the determinants
of (sub-)matrices with reciprocal condition numbers
smaller than argument `tol`

but sets the corresponding principal minors to (exactly) zero.
The number of principal minors of an *N x N* matrix is
*∑_{k=1}^N ( N* choose * k )*,
which gets very large for large matrices.
Therefore, it is not recommended to use method `"det"`

for matrices with, say, more than 12 rows/columns.

If method `"eigen"`

(default for matrices with 13 or more rows/columns) is used,
`isSemidefinite()`

checks whether all eigenvalues
of the matrix `m`

(or of the matrix `-m`

if argument `positive`

is `FALSE`

)
are larger than `-tol`

.
In case of a singular or nearly singular matrix,
some eigenvalues
that theoretically should be zero
can considerably deviate from zero
due to rounding errors,
which are unavoidable on digital computers.
`isSemidefinite()`

uses the following procedure
to reduce the probability of incorrectly returning `FALSE`

due to rounding errors in the calculation of eigenvalues
of singular or nearly singular matrices:
if the reciprocal condition number of an *NxN* matrix
is smaller than argument `tol`

and not all of the eigenvalues of this matrix are larger than `-tol`

,
`isSemidefinite()`

checks
whether all *( N* choose * (N-k) )*
*(N-k) x (N-k)* submatrices
are positive semidefinite,
where *k* with *0 < k < N* is the number of eigenvalues
in the interval `-tol`

and `tol`

.
If necessary, this procedure is done recursively.

Please note that a matrix can be neither positive semidefinite nor negative semidefinite.

`isSemidefinite()`

and `semidefiniteness()`

return a locigal value (if argument `m`

is a matrix)
or a logical vector (if argument `m`

is a list)
indicating whether the matrix (or each of the matrices)
is positive/negative (depending on argument `positive`

)
semidefinite.

Arne Henningsen

Chiang, A.C. (1984):
*Fundamental Methods of Mathematical Economics*,
3rd ed., McGraw-Hill.

Gantmacher, F.R. (1959):
*The Theory of Matrices*,
Chelsea Publishing.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ```
# a positive semidefinite matrix
isSemidefinite( matrix( 1, 3, 3 ))
# a negative semidefinite matrix
isSemidefinite( matrix(-1, 3, 3 ), positive = FALSE )
# a matrix that is positive and negative semidefinite
isSemidefinite( matrix( 0, 3, 3 ))
isSemidefinite( matrix( 0, 3, 3 ), positive = FALSE )
# a matrix that is neither positive nor negative semidefinite
isSemidefinite( symMatrix( 1:6 ) )
isSemidefinite( symMatrix( 1:6 ), positive = FALSE )
# checking a list of matrices
ml <- list( matrix( 1, 3, 3 ), matrix(-1, 3, 3 ), matrix( 0, 3, 3 ) )
isSemidefinite( ml )
isSemidefinite( ml, positive = FALSE )
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.