Hi All, I need to evaluate a series expansion using Legendre polynomials. Using the 'orthopolinom' package I can get a list of the first n Legendre polynomials as character strings.> library(orthopolynom) > l<-legendre.polynomials(4) > l[[1]] 1 [[2]] x [[3]] -0.5 + 1.5*x^2 [[4]] -1.5*x + 2.5*x^3 [[5]] 0.375 - 3.75*x^2 + 4.375*x^4 But I can't figure out how to implement functions that could be evaluated for arbitrary 'x', from this list, Thanks for your help. Ariel./ -- Dr. Ariel Chernomoretz Departamento de Fisica, FCEyN, Universidad de Buenos Aires, (1428) Ciudad Universitaria, Ciudad de Buenos Aires, Argentina. TE +54 11 4576 3390 ext 817 Fax +54 11 4576 3357 email: ariel at df.uba.ar Webpage: http://www.df.uba.ar/users/ariel
On 17/10/2008, at 7:40 AM, Chernomoretz Ariel wrote:> Hi All, > I need to evaluate a series expansion using Legendre polynomials. > Using the 'orthopolinom' package I can get a list of the first n > Legendre polynomials as character strings. > >> library(orthopolynom) >> l<-legendre.polynomials(4) >> l > [[1]] > 1 > > [[2]] > x > > [[3]] > -0.5 + 1.5*x^2 > > [[4]] > -1.5*x + 2.5*x^3 > > [[5]] > 0.375 - 3.75*x^2 + 4.375*x^4 > > But I can't figure out how to implement functions that could be > evaluated for arbitrary 'x', from this list, > Thanks for your help.?as.function methods(as.function) ?as.function.polynomial foo <- as.function(l[[4]]) foo(3) cheers, Rolf Turner ###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
try this: library(orthopolynom) l <- legendre.polynomials(4) fun.l <- lapply(l, as.function) fun.l[[3]](1:3) I hope it helps. Best, Dimitris Chernomoretz Ariel wrote:> Hi All, > I need to evaluate a series expansion using Legendre polynomials. > Using the 'orthopolinom' package I can get a list of the first n > Legendre polynomials as character strings. > >> library(orthopolynom) >> l<-legendre.polynomials(4) >> l > [[1]] > 1 > > [[2]] > x > > [[3]] > -0.5 + 1.5*x^2 > > [[4]] > -1.5*x + 2.5*x^3 > > [[5]] > 0.375 - 3.75*x^2 + 4.375*x^4 > > But I can't figure out how to implement functions that could be > evaluated for arbitrary 'x', from this list, > Thanks for your help. > > Ariel./ > >-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014
Try this (to evaluate them at 10): polynomial.values(l, 10) On Thu, Oct 16, 2008 at 2:40 PM, Chernomoretz Ariel <algo107 at gmail.com> wrote:> Hi All, > I need to evaluate a series expansion using Legendre polynomials. > Using the 'orthopolinom' package I can get a list of the first n > Legendre polynomials as character strings. > >> library(orthopolynom) >> l<-legendre.polynomials(4) >> l > [[1]] > 1 > > [[2]] > x > > [[3]] > -0.5 + 1.5*x^2 > > [[4]] > -1.5*x + 2.5*x^3 > > [[5]] > 0.375 - 3.75*x^2 + 4.375*x^4 > > But I can't figure out how to implement functions that could be > evaluated for arbitrary 'x', from this list, > Thanks for your help. > > Ariel./ > > > -- > Dr. Ariel Chernomoretz > Departamento de Fisica, FCEyN, Universidad de Buenos Aires, > (1428) Ciudad Universitaria, Ciudad de Buenos Aires, Argentina. > TE +54 11 4576 3390 ext 817 > Fax +54 11 4576 3357 > email: ariel at df.uba.ar Webpage: http://www.df.uba.ar/users/ariel > > ______________________________________________ > 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. >