matrixPower {lavaSearch2} | R Documentation |
Power of a Matrix
Description
Compute the power of a matrix.
Usage
matrixPower(object, power, symmetric, tol = 1e-12, print.warning = TRUE)
Arguments
object |
a matrix. |
power |
[numeric] power to be applied to the matrix. |
symmetric |
[logical] is the matrix symmetric? Argument passed to the function |
tol |
[numeric >0] the threshold under which the eigenvalues are set to 0. |
print.warning |
[logical] should a warning be print when some or the eigenvalues are not strictly positive. |
Value
A matrix.
Examples
## symmetric matrix
set.seed(10)
M <- matrix(rnorm(20*6),20,6)
Sigma <- var(M)
Sigma.half <- matrixPower(Sigma, power = 1/2, symmetric = TRUE)
round(Sigma.half %*% Sigma.half - Sigma,5)
iSigma <- matrixPower(Sigma, power = -1, symmetric = TRUE)
round(iSigma %*% Sigma,5)
iSigma.half <- matrixPower(Sigma, power = -1/2, symmetric = TRUE)
round(iSigma.half %*% iSigma.half - iSigma,5)
## non symmetric matrix
set.seed(10)
M <- matrix(abs(rnorm(9)), 3, 3) + diag(1,3,3)
M-t(M)
iM <- matrixPower(M, power = -1, symmetric = FALSE)
round(iM %*% M,5)
iM.half <- matrixPower(M, power = -1/2, symmetric = FALSE)
round(iM.half %*% iM.half %*% M,5)
[Package lavaSearch2 version 2.0.3 Index]