[R] matrix limit
Ben Bolker
bbolker at gmail.com
Wed Nov 10 15:59:21 CET 2010
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)
More information about the R-help
mailing list