[S] Matrix Square Root

Erin Hodgess (hodgess@uhdux2.dt.uh.edu)
Tue, 21 Apr 1998 17:16:57 -0500


Dear Fei:

There's not a direct function to take the square root of a matrix,
but this is what you do:

If your matrix has real non-neg. eigenvalues, real eigenvectors, is
invertible, then the sqrt(X) =
Eigvectors %*% Diag(sqrt(Eigenvalues)) %*% (Eigenvectors)^(-1).

Here is a little function to get you started:

sqrt1 <- function(x) {
xe <- eigen(x)
xe1 <- xe$values
if(all(xe1 >= 0)) {
xev1 <- diag(sqrt(xe1))
}
xval1 <- cbind(xe$vectors)
xval1i <- solve(xval1)
y <- xval1 %*% xev1 %*% xval1i
}

Good luck!

Sincerely,
Erin Hodgess
Assistant Professor
Dept. of Computer and Mathematical Sciences
University of Houston -- Downtown
e-mail: hodgess@uhdux2.dt.uh.edu

From: Fei Chen <fchen@stern.nyu.edu>
To: s-news@wubios.wustl.edu
Subject: [S] matrix square root
Message-Id: <Pine.GSO.3.96.980421175203.21528K-100000@rnd.Stern.nyu.edu>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Sender: owner-s-news@wubios.wustl.edu
Status: R

hi all,

this might be a thing easy to do. but i don't know how:
in MATLAB, there is a function sqrtm() which takes the square root of a
matrix, as opposed to sqrt() which takes the square root of every element
in a matrix.

is there a similar function in S+ like sqrtm()?

thanks a lot,

fei

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news