[R] How to calculte the power of a matrix

Steve Lianoglou mailinglist.honeypot at gmail.com
Fri Dec 11 20:23:56 CET 2009


Hi,

On Dec 11, 2009, at 2:01 PM, Moohwan Kim wrote:

> Dear R family
> 
> I have a following question.
> Suppose I have a matrix as follows, for instance:
> tau=
> 0 1 0 0 0
> 0 0 1 0 0
> 0 0 0 1 0
> 0 0 0 0 1
> 1 0 0 0 0
> 
> I want to calculate (-m) power of tau, for example, m=893.
> 
> When I run tau^2, the outcome is just tau.

That's because 1^2 = 1

R> tau[tau == 1] <- 2
R> tau^2
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    0    4
[2,]    4    0    0    0    0
[3,]    0    4    0    0    0
[4,]    0    0    4    0    0
[5,]    0    0    0    4    0

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact




More information about the R-help mailing list