R中矩阵总和的计算

时间:2019-10-11 14:11:24

标签: r rstudio

我在考虑问题。如何计算R

Image of LaTeX equation

(A方阵,k-任何自然数),是否不包含“ for”?

1 个答案:

答案 0 :(得分:0)

如果我正确解释了您的表示法,也许在基本R中是这样的...

A <- matrix(c(1,2,3,4), nrow = 2)                         #example matrix

k <- 10

B <- Reduce(`%*%`, (rep(list(A), k)), accumulate = TRUE)  #list of A^(1:k)

BB <- lapply(1:k, function(k) B[[k]]/k)                   #list of A^(1:k)/k

Reduce(`+`, BB)                                           #sum of series BB

         [,1]    [,2]
[1,] 603684.8 1319741
[2,] 879827.1 1923425