> 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???
Take a look at FAQ on R 7.21 ("How can I turn a string into a variable?"). This code will do what you ask (though the first matrix is named P.1, rather than P for convenience): paste0 <- function(x) paste("P.", x, sep="") P.1 <- matrix(rnorm(25), nrow=5) varnames <- paste0(1:10) for(i in 2:10) assign(paste0(i), get(paste0(i-1)) %*% P.1) Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} ______________________________________________ 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.