On Sun, Jul 22, 2012 at 05:34:08PM -0700, bilelsan wrote: > Hi, > Thanks a lot for answer. It is what I mean. > But the code does not seem to work (
Hi. I am sorry for a late reply. I was on vacations one week. Can you specify the problem? I get e1 <- 2 e2 <- 3 k <- 3 f <- 0 for (r in 1:k) { f <- f + 1/factorial(r) * sum(e1^(r:0)*e2^(0:r)) } f [1] 25.33333 If this the correct answer? The code may be put to a function. getF <- function(e1, e2, k) { f <- 0 for (r in 1:k) { f <- f + 1/factorial(r) * sum(e1^(r:0)*e2^(0:r)) } f } getF(2, 3, 3) [1] 25.33333 Hope this helps. Petr Savicky. > > Le Jul 19, 2012 ?? 8:52 AM, Petr Savicky [via R] a ??crit : > > > On Wed, Jul 18, 2012 at 06:02:27PM -0700, bilelsan wrote: > > > Leave the Taylor expansion aside, how is it possible to compute with [R]: > > > f(e) = e1 + e2 #for r = 1 > > > + 1/2!*e1^2 + 1/2!*e2^2 + 1/2!*e1*e2 #for r = 2, excluding e2*e1 > > > + 1/3!*e1^3 + 1/3!*e1^2*e2 + 1/3!*e2^2*e1 + 1/3!*e2^3 #for r = 3, > > > excluding > > > e2*e1^2 and e1*e2^2 > > > + ... #for r = k > > > In other words, I am trying to figure out how to compute all the possible > > > combinations as exposed above. > > > > Hi. > > > > For a general r, do you mean the following sum of products? > > > > 1/r! (e1^r + e1^(r-1) e2 + ... e1 e2^(r-1) + e2^r) > > > > If this is correct, then try > > > > f <- 0 > > for (r in 1:k) { > > f <- f + 1/factorial(r) * sum(e1^(r:0)*e2^(0:r)) > > } > > > > Hope this helps. > > > > Petr Savicky. > > > > ______________________________________________ > > [hidden email] 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. > > > > > > If you reply to this email, your message will be added to the discussion > > below: > > http://r.789695.n4.nabble.com/Re-taylor-expansions-with-real-vectors-tp4636948p4636989.html > > To unsubscribe from Re: taylor expansions with real vectors, click here. > > NAML > > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Re-taylor-expansions-with-real-vectors-tp4636948p4637388.html > Sent from the R help mailing list archive at Nabble.com. > [[alternative HTML version deleted]] > > ______________________________________________ > 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. ______________________________________________ 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.