R/matrix.sqrt.r

########## S-function: matrix.sqrt ##########

# Computes the positive square-root of a square
# positive definite matrix.

# Last changed: 05/06/97

matrix.sqrt <- function(A)
{
   sva <- svd(A)
   if (min(sva$d)>=0)
      Asqrt <- t(sva$v %*% (t(sva$u) * sqrt(sva$d)))
   else
      stop("Matrix square root is not defined")
   return(Asqrt)
}

######### End of S-function matrix.sqrt ########

Try the SemiPar package in your browser

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

SemiPar documentation built on May 2, 2019, 5:42 a.m.