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

From: Atte Tenkanen <attenka_at_utu.fi>
Date: Sun, 06 May 2007 12:07:07 +0300


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



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 06 May 2007 - 09:12:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 07 May 2007 - 22:31:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.