Skip to contents

Check if a matrix is positive definite This function checks whether a given matrix is positive definite, i.e., all of its eigenvalues are positive.

Usage

is_positive_definite(mat)

Arguments

mat

The matrix to be checked.

Value

A logical value indicating whether the matrix is positive definite.

Examples

# Create a positive definite matrix
mat1 <- matrix(c(4, 2, 2, 3), nrow = 2)
is_positive_definite(mat1)
#> [1] TRUE
# Expected output: TRUE

# Create a non-positive definite matrix
mat2 <- matrix(c(4, 2, 2, -3), nrow = 2)
is_positive_definite(mat2)
#> [1] FALSE
# Expected output: FALSE

# Check an empty matrix
mat3 <- matrix(nrow = 0, ncol = 0)
is_positive_definite(mat3)
#> [1] TRUE
# Expected output: TRUE