Hi Pascal,

I think the function could be better but try this:

# Function: M is your matrix and n MUST be an integer>0
mat.pow<-function(M,n) {
  result<-M
    if(n>1){
       for ( iter in 2:n) result<-M%*%result
       result
           }
    else {result}
  result
 }

# The matrix
m <-  rbind(c(1,1,0), c(0,1,1), c(0,0,1))

# Goal m^2 = m x m
goal=m%*%m

# matpow
res=mat.pow(m,2)

# Check point
all.equal(goal,res)

See RSiteSearch('nth step transition matrices')


HTH,

Jorge


On Tue, May 6, 2008 at 1:37 AM, pascal vrolijk <pascalvrolijk@hotmail.com>
wrote:

> Hello best helpers,
>
> I am a new user and I have been struggling for hours. So finally I decide
> to ask you:
> If I have a matrix P, and P.2 = P%*%P, and P.3=P.2%*%P
> is there a function to calculate the power of a matrix?? if not how can i
> do:
> for (i in 1:10)  {P.i=P^i}
> after this I need to sum them up and my problem is to combine P and i to
> P.i  can anyone help me please???
>
> Thanks and have a nice day,
>
> Pascal.
>
>
> _________________________________________________________________
> [[elided Hotmail spam]]
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org 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.

	[[alternative HTML version deleted]]

