##' This function computes negative half power of a square matrix x based on eigenvectors and eigenvalues.
##'
##' The Negative Half Matrix power is computed by eigenvectors and eigenvalues. X^(-1/2) = UΛ^(-1/2)U* where X is a hermitian matrix, 𝑈 is a unitary matrix with columns the eigenvectors of matrix X, 𝑈∗ is the conjugate transpose of matrix 𝑈 and Λ is a diagonal matrix with entries the eigenvalues of matrix X. If the negative half power of input matrix does not exist, the result matrix might have NaN.
##' @title The Negative Half Power of a Matrix
##' @param x matrix
##' @return x^(-1/2)
##' @author Xiulin Xie
##' @export
##' @examples
##' Nhalf_power(matrix(c(1, 0.4, 0.4, 1), nrow = 2))
Nhalf_power <- function(x) {
n = -1/2
v1 <- eigen(x)$values
v2 <- eigen(x)$vectors
y <- v2 %*% (v1^n * t(v2))
return(y)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.