H i, all!
First of all, I'd like to apologize for my poor English. It's for years
I don't use it.
This is a R-version of a function I wrote a long ago for my HP48 calculator.
It works with the binary expression of the power and just need to
duplicate the mem used by X.
Hope this helps.
mtx.exp<-function(X,n)
#Function to calculate the n-th power of a matrix X;
{
phi <- diag(rep(1,length(X[1,])))
pot <- X #This is the first power of the matrix.
while (n > 0)
{
if (n%%2)
{
phi <- phi%*%pot;
}
n <- n%/%2;
pot <- pot %*% pot;
}
return(phi);
}
#Here is some output:
> xx <- matrix(c(1,0,1,1),2,2)
> xx
[,1] [,2]
[1,]11
[2,]01
> mtx.exp(xx,3)
[,1] [,2]
[1,]13
[2,]01
> mtx.exp(xx,4)
[,1] [,2]
[1,]14
[2,]01
> mtx.exp(xx,6)
[,1] [,2]
[1,]16
[2,]01
> mtx.exp(xx,10)
[,1] [,2]
[1,]1 10
[2,]01
> mtx.exp(xx,1000)
[,1] [,2]
[1,]1 1000
[2,]01
Vicente D. Canto Casasola
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html