[R] A function for raising a matrix to a power?

Atte Tenkanen attenka at utu.fi
Sun May 6 11:07:07 CEST 2007


Hi,

Is there a function for raising a matrix to a power? For example if you like to compute A%*%A%*%A, is there an abbreviation similar to A^3?

Atte Tenkanen

> A=rbind(c(1,1),c(-1,-2))
> A
     [,1] [,2]
[1,]    1    1
[2,]   -1   -2
> A^3
     [,1] [,2]
[1,]    1    1
[2,]   -1   -8

But:

> A%*%A%*%A
     [,1] [,2]
[1,]    1    2
[2,]   -2   -5



More information about the R-help mailing list