[R] how to apply summation sign formula to R
Berend Hasselman
bhh at xs4all.nl
Sun Aug 25 07:12:43 CEST 2013
On 24-08-2013, at 23:13, Sebastian Hersberger <sebastian.hersberger at unibas.ch> wrote:
> Thanks. I restate my problem/question and hope its better understandable now.
>
> Let us define A and B as kxk matrices. C is the output (matrix), which I try to calculate for differnt i values.
>
> So for example: I want to caluclate the matrix C for the value i=10:
>
> Therefore, I set:
>
> i <- c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
>
> Finally, I have to define the summation formula in R. My question is how this following summation formula has to be applied to R.
>
> The arithmetic form of the formula equals:
>
> C = (Σ(from i=0 to i) A^i ) x B x (Σ(from i=0 to i) A^i )’
>
> Which means:
> matrix C equals the sum from i=0 to i times matrix A to the power of i
> times matrix B
> times the transposed/invers of the sum from i=0 to i times matrix A to the power of i
This is not the same (inner) summation as in the first post where i starts at 1 and goes to j-1.
Original: (Σ_(i=1)^(j-1) A^i ) B (Σ_(i=1)^(j-1) A^i)’
That made me wonder what is supposed to happen when j=1? (Originally j started at 1 and stopped at n)
David's solution can be wrapped in a function like this
genAsum <- function(A,n,B) {
tmp <- Reduce("+", lapply(0:n, FUN=function(j) A%^%j))
tmp %*% B %*% t(tmp)
}
Berend
More information about the R-help
mailing list