# ---------------------------------------------------------------------------- #
#' Check if a matrix is invertible
#'
#' Checks a matrix to see if it is invertible.
#'
#' @param x A numeric matrix which should be checked to see if it is invertible.
#'
#' @return TRUE if the supplied matrix is invertible, FALSE otherwise.
#'
#' @examples
#' is_invertible(matrix(c(1, 2, 2, 1), 2, 2)) # => TRUE
#'
#' is_invertible(matrix(c(1, 1, 1, 1), 2, 2)) # => FALSE
#'
#' @export
#'
is_invertible <- function(x) {
res <- tryCatch(
{
solve(x)
},
error = function(e) {
e
}
)
if (inherits(res, "error")) {
FALSE
} else {
TRUE
}
}
# ---------------------------------------------------------------------------- #
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.