R/inv_matrix_sqrt.R

Defines functions inv_matrix_sqrt

Documented in inv_matrix_sqrt

#' Inverse square root matrix
#'
#' @keywords internal
#' @param M the matrix
#' @return the inverse matrix square rooted
inv_matrix_sqrt <- function(M) {
  if (NROW(M) > 1) {
    eva_ve <- eigen(M)
    S <- diag(sqrt(1/eva_ve$values)) %*% t(eva_ve$vectors)
  } else {
    S <- 1 / sqrt(M)
  }
  return(S)
}
Marga8/HDGCvar documentation built on May 25, 2024, 11:12 a.m.