zhiji19 <zhiji19 <at> gmail.com> writes:

> I need to write R code for lim(I+X/n)^n with "repeat loop". (note: limit is
> n from 1 to infinity, I is identity matrix, X is square symmetric matrix)
> Can anyone please provide help with my question.
> 

 Here's a more efficient solution. If you *need* to use a repeat { }
loop, then I am guessing this would be a homework problem ... see
?"repeat" (although that does not actually provide very much guidance ...)

library(expm)  ## needs to be installed first

z <- matrix(1:9,nrow=3)

tmpf <- function(M,n) {
  (diag(nrow(M))+M/n)%^%n
}
tmpf(z,1)
tmpf(z,20)
tmpf(z,100)

______________________________________________
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.

Reply via email to