On Aug 24, 2013, at 6:43 PM, David Winsemius wrote: > > On Aug 24, 2013, at 2:13 PM, Sebastian Hersberger 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 > > That first term might be (untested in absence of test data by questioner) : > > require(expm) > res1 <- Reduce("+", lapply(1:i, function(i) powm(A, i) ) )
I did test it and both my memory about the functions name and its operation were wrong. Try: res1 <- Reduce("+", lapply(1:i, function(i) A %^% i) ) > >> times matrix B > > res2 <- res1 %*% B > >> times the transposed/invers of the sum from i=0 to i times matrix A to the >> power of i >> > Well, the transpose was not generally the inverse when I took linear algebra, > but as I said I didn't make it to all the sessions. (I'm assuming it is the > transpose.) > > res3 <- res2 %*% t(res1) > > You could probably do it all in one line, but I like to check my itermediates. > > -- > David. > >> I hope I were able to specify my problem in an understandable way. If not, >> please let me know. >> >> Thanks and regards >> Sebastian >> >> ________________________________________ >> From: David Winsemius [dwinsem...@comcast.net] >> Sent: Saturday, August 24, 2013 8:35 PM >> To: Sebastian Hersberger >> Cc: r-help@r-project.org >> Subject: Re: [R] how to apply summation sign formula to R >> >> On Aug 24, 2013, at 6:37 AM, Sebastian Hersberger wrote: >> >>> Hi all >>> >>> I have a short question relating to the usage of the summation sign in R. >>> >>> Let's define A and B as two kxk matrice. >>> My goal is to calculate the matrix C for the periods from 1 to 200 >>> (n=1-200). >>> >>> C^(n) = Σ_(j=1)^n [(Σ_(i=1)^(j-1) A^i ) B (Σ_(i=1)^(j-1) A^i)’ ] >>> >>> How has that to be implemented in R (lets say for example for period = n = >>> 150)? >> >> I don't follow all this notation but you might want to look at the expm >> package that has a powm function. It's possible that the expm function may >> do what you want, but as I said I was unclear what the equation was >> attempting to do. Perhaps if you explained the steps in mathematical >> language, then other viewers who actually woke up to attend their linear >> algebra course might have a better chance of offering assistance. >> >> ( When I saw the earlier copy yesterday, I had hopes that such wiser viewers >> might chime in and still have such hopes.) >> >> -- >> >> David Winsemius >> Alameda, CA, USA >> > > David Winsemius > Alameda, CA, USA > > ______________________________________________ > 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. David Winsemius Alameda, CA, USA ______________________________________________ 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.