https://github.com/cran/pracma
Raw File
Tip revision: 267abaa96cae63dd7872bb21b2613bd067b0a9f4 authored by Hans W. Borchers on 30 January 2018, 13:20:01 UTC
version 2.1.4
Tip revision: 267abaa
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 (class(e) == "try-error") {
            a <- FALSE
        } else {
            a <- TRUE
        }
    }
    return(a)
}
back to top