Dear list, I have a big deal concerning the development of a Taylor expansion. require(Matrix) e1 <- as.vector(1:5) e2 <- as.vector(6:10) in order to obtain all the combinations between these two vectors following a Taylor expansion (or more simply through a Maclaurin series) for real numbers. We have f(x) = f(0) + f'(0)(x-0) + f''(0)(x-0)^2/2! + ? + f^(k)(0)(x-0)^k/k! with f(x) = e1 + e2 for Taylor expansion (r = 1) + 1/2!*e1^2 + 1/2!*e2^2 + 1/2!*e1*e2 for Taylor expansion (r = 2) excluding e2*e1 + 1/3!*e1^3 + 1/3!*e1^2*e2 + 1/3!*e2^2*e1 + 1/3!*e2^3 for Taylor expansion (r = 3) excluding e2*e1^2 and e1*e2^2 ... I already write the number of possible combinations as : x <- as.vector(0) for (r in 1:r){x[r] <- 2*(sum(choose(2*q+r-1,r))-sum(choose(q+r-1,r)))}# q: number of lag of e1 and e2; r: order of taylor expansion nstar <- sum(x) # N* number of total combinations How to write f(x) in a general framework? Quid of this framework when e1 and e2 are completed with their lags if q > 1? Your help or advice would be greatly appreciated Bilel -- View this message in context: http://r.789695.n4.nabble.com/RE-taylor-expansions-with-real-vectors-tp4636886.html Sent from the R help mailing list archive at Nabble.com.
On Wed, Jul 18, 2012 at 9:47 AM, bilelsan <sanbilel at yahoo.fr> wrote:> Dear list, > > I have a big deal concerning the development of a Taylor expansion. > > require(Matrix) > e1 <- as.vector(1:5) > e2 <- as.vector(6:10) > > in order to obtain all the combinations between these two vectors following > a Taylor expansion (or more simply through a Maclaurin series) for real > numbers. > We have f(x) = f(0) + f'(0)(x-0) + f''(0)(x-0)^2/2! + ? + f^(k)(0)(x-0)^k/k! > with > f(x) = e1 + e2 for Taylor expansion (r = 1) > + 1/2!*e1^2 + 1/2!*e2^2 + 1/2!*e1*e2 for Taylor expansion (r = 2) > excluding e2*e1 > + 1/3!*e1^3 + 1/3!*e1^2*e2 + 1/3!*e2^2*e1 + 1/3!*e2^3 for Taylor > expansion (r = 3) excluding e2*e1^2 and e1*e2^2 > ... > I already write the number of possible combinations as : > x <- as.vector(0) > for (r in 1:r){x[r] <- 2*(sum(choose(2*q+r-1,r))-sum(choose(q+r-1,r)))}# q: > number of lag of e1 and e2; r: order of taylor expansion > nstar <- sum(x) # N* number of total combinations > > How to write f(x) in a general framework? > Quid of this framework when e1 and e2 are completed with their lags if q > > 1? > Your help or advice would be greatly appreciated >See the section on Taylor expansions in the Ryacas package vignette. Depending on what you want to do that may or may not be relevant. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
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. -- View this message in context: http://r.789695.n4.nabble.com/Re-taylor-expansions-with-real-vectors-tp4636948p4636978.html Sent from the R help mailing list archive at Nabble.com.
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.
Hi, Thanks a lot for answer. It is what I mean. But the code does not seem to work ( 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]]
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 at 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.
Thanks for specifying the solution. The deal is that we are faced of vectors. Moreover I need to specify them as function of own-lagged with expansion=1,2, ? ; lag=1, 2, ? set.seed(1) E <- cbind(as.vector(rnorm(10)),as.vector(rnorm(10)),as.vector(rnorm(10))) #or more vectors; here 3 for illustration Elag <- embed(x=E,2) #for lag = 1 The deal is to obtain All the combinations without duplicates and including the lags. The expansion have to lead to: for expansion = 1 ::> cbind(Elag[,1],Elag[,2],Elag[,3],Elag[,4],Elag[,5],Elag[,6]) for expansion = 2 ::> we add cbind(Elag[,1]^2,Elag[,2]^2,Elag[,3]^2,Elag[,4]^2,Elag[,5]^2,Elag[,6]^2); cbind(Elag[,1]*Elag[,2], Elag[,1]*Elag[,3],Elag[,1]*Elag[,4],Elag[,1]*Elag[,5],Elag[,1]*Elag[,6]); cbind(Elag[,2]*Elag[,3],Elag[,2]*Elag[,4],Elag[,2]*Elag[,5],Elag[,2]*Elag[,6]); cbind(Elag[,3]*Elag[,4]*Elag[,5], ? and so on for expansion = 3 ::> we add cbind(Elag[,1]^3,Elag[,2]^3,Elag[,3]^3,Elag[,4]^3,Elag[,5]^3,Elag[,6]^3); cbind(Elag[,1]^2*Elag[,2],Elag[,1]^2*Elag[,3],Elag[,1]^2*Elag[,4],Elag[,1]^2*Elag[,5],Elag[,1]^2*Elag[,6]); and so on ... cbind(Elag[,1]*Elag[,2]*Elag[,3],Elag[,1]*Elag[,2]*Elag[,4], Elag[,1]*Elag[,2]*Elag[,5], and so on ? for expansion =4 , ? This is what I called Taylor expansion even if we are faced of real vectors. And I need to keep all these vectors obtained by the expansion considering other lags (1, 2, 3, ?) and other degree of expansion (1, 2, 3, ?). How could it be automatized? Thanks for help, I tried for couple of day and I am not able to compute this. Any advice is very welcome. Bill -- View this message in context: http://r.789695.n4.nabble.com/Re-taylor-expansions-with-real-vectors-tp4636948p4638811.html Sent from the R help mailing list archive at Nabble.com.