I'm trying to compute the -0.5 power of the following matrix:
S <- matrix(c(0.088150041, 0.001017491 , 0.001017491, 0.084634294),nrow=2)
In Matlab, the result is (S^(-0.5)
):
S^(-0.5)
ans =
3.3683 -0.0200
-0.0200 3.4376
Power of a matrix in RThe matrix must be square to calculate the power, as the number of columns must be equal to the number of rows to compute the calculations. Note that if you want to calculate the element-wise power you just need to use the ^ operator. In this case the matrix don't need to be square.
If 𝐴 is a square matrix and 𝑘 is a positive integer, the 𝑘 t h power of 𝐴 is given by 𝐴 = 𝐴 × 𝐴 × ⋯ × 𝐴 , where there are 𝑘 copies of matrix 𝐴 .
The exponentiation n (with n a nonzero real number) of an invertible square matrix M can be defined by Mn=exp(nlogM) M n = exp and therefore the power of the matrix can be calculated with a decimal number as the exponent.
> library(expm)
> solve(sqrtm(S))
[,1] [,2]
[1,] 3.36830328 -0.02004191
[2,] -0.02004191 3.43755429
After some time, the following solution came up:
"%^%" <- function(S, power)
with(eigen(S), vectors %*% (values^power * t(vectors)))
S%^%(-0.5)
The result gives the expected answer:
[,1] [,2]
[1,] 3.36830328 -0.02004191
[2,] -0.02004191 3.43755430
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With