R/is.posDef.R

Defines functions is.posDef

Documented in is.posDef

#' Positive definited matrices
#'
#' @description Checks if a given matrix is positive definited
#' @param matrix a (non-empty) numeric matrix of data values.
#'
#' @return A logical value: True/False.
#'
#' @examples
#' A <- matrix(c(1,2,2,1), nrow = 2, byrow = TRUE)
#' is.posDef(A)
#'
#' B <- matrix(c(1,2,3,3,1,2,1,2,1), nrow = 3, byrow = TRUE)
#' is.posDef(B)
#'
#' @export
is.posDef <- function(matrix){ #comprobacion matriz es definida positiva
  if ( isSymmetric(matrix) && all(eigen(matrix)$values > 0) )
    return(TRUE)

  else
    return(FALSE)
}

Try the stats4teaching package in your browser

Any scripts or data that you put into this service are public.

stats4teaching documentation built on Oct. 4, 2022, 9:06 a.m.