Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compute the power of a matrix in R [duplicate]

Tags:

r

matrix

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
like image 572
WAF Avatar asked Apr 23 '13 15:04

WAF


People also ask

How do you find the power of a matrix in R?

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.

How do you find a formula of the power of a matrix?

If 𝐴 is a square matrix and 𝑘 is a positive integer, the 𝑘 t h power of 𝐴 is given by 𝐴 = 𝐴 × 𝐴 × ⋯ × 𝐴 ,  where there are 𝑘 copies of matrix 𝐴 .

How do you solve a matrix to the power n?

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.


2 Answers

> library(expm)
> solve(sqrtm(S))
            [,1]        [,2]
[1,]  3.36830328 -0.02004191
[2,] -0.02004191  3.43755429
like image 76
caracal Avatar answered Sep 20 '22 17:09

caracal


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
like image 33
WAF Avatar answered Sep 20 '22 17:09

WAF