powered by
sqrtm(x)
x
all.equal( S %*% S , M )
The method works from the Schur decomposition.
expm
logm
m <- diag(2) sqrtm(m) == m # TRUE (m <- rbind(cbind(1, diag(1:3)),2)) sm <- sqrtm(m) sm zapsmall(sm %*% sm) # Zap entries ~= 2e-16 stopifnot(all.equal(m, sm %*% sm))
Run the code above in your browser using DataLab