expm (version 0.999-4)

sqrtm: Matrix Square Root

Description

This function computes the matrix square root of a square matrix. The sqrt of a matrix \(A\) is \(S\) such that \(A = S S\).

Usage

sqrtm(x)

Arguments

x

a square matrix.

Value

A matrix ‘as x’ with the matrix sqrt of x.

Details

The matrix square root \(S\) of \(M\), \(S = sqrtm(M)\) is defined as one (the “principal”) \(S\) such that \(S S = S^2 = M\), (in R, all.equal( S %*% S , M )).

The method works from the Schur decomposition.

References

Higham, N.~J. (2008). Functions of Matrices: Theory and Computation; Society for Industrial and Applied Mathematics, Philadelphia, PA, USA.

See Also

expm, logm

Examples

Run this code
# NOT RUN {
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