# Positive or Negative Semidefiniteness

### Description

Check whether a symmetric matrix is positive or negative semidefinite.

### Usage

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, ... )
``` |

### Arguments

`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 |

### Details

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`

.
Due to rounding errors,
which are unavoidable on digital computers,
those eigenvalues of a singular matrix
that 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 eigenvalues
of an *NxN* matrix with reciprocal condition number
smaller than argument `tol`

but checks whether all *N*
*(N-1)x(N-1)* submatrices
with row *i* and column *i*, *i = 1, ..., N*, removed
are positive semidefinite.
If necessary, this procedure is done recursively.

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

### Value

`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.

### Author(s)

Arne Henningsen

### References

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

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

### Examples

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 )
``` |