R/matrix.sqrt.r

Defines functions matrix.sqrt

Documented in matrix.sqrt

########## 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 April 16, 2018, 5:05 p.m.