https://github.com/cran/pracma
Tip revision: c1688b374d201c13fb40b4dda2d2a89e34b94ec6 authored by Hans W. Borchers on 23 January 2021, 09:10:02 UTC
version 2.3.3
version 2.3.3
Tip revision: c1688b3
isposdef.R
isposdef <- function(A, psd = FALSE, tol = 1e-10) {
if (nrow(A) != ncol(A)) {
warning("Matrix 'A' is not quadratic.\n", .call = FALSE)
a <- FALSE
} else if (any(abs(A - t(A)) > tol)) {
warning("Matrix 'A' is not symmetric.\n", .call = FALSE)
a <- FALSE
} else {
e <- try(chol(A, pivot = psd), silent = TRUE)
if(inherits(e, "try-error")) {
a <- FALSE
} else {
a <- TRUE
}
}
return(a)
}