#' Invert Symmetric Positive Definite Matrix via Cholesky Decomposition
#'
#' Consider a matrix that is symmetric and has positive eigenvalues, and is
#' therefore positive definite. Then finds the inverse of the cholesky
#' decomposition of this matrix as a more numerically stable alternative
#' to `base::solve(x)`.
#'
#' @param x matrix. symmetric (up to `tol`) and positive definite.
#' @param tol numeric. Differences of symmetry smaller than this value
#' are not considered significant.
#'
#' @return the matrix inverse of `x`.
#'
#' @export
chol_solve <- function(x, tol = 100 * .Machine$double.eps) {
stopifnot(
"x is not symmetric" = isSymmetric(x, tol),
"x is not positive definite" = all(eigen(x)$values > tol)
)
return(chol2inv(chol(x)))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.