Alaios wrote: > x<-legendre.polynomials(2)[[3]] >> x > -0.5 + 1.5*x^2 > >> str(x) > Class 'polynomial' num [1:3] -0.5 0 1.5 > > As you can see from the code above str(x) returns that x is of class > polynomial. I want to use that polynomial as a function. The reason for > that is that I would be grateful if I can feed that kind of function > inside integrate(f,lower=,upper=)
You can use the ‘as.function’ function. But if you’re just going to integrate the polynomial anyway, why don’t you just use the ‘integral’ function? It’s much more accurate than using numerical integration. BTW, to see which functions handle ‘polynomial’ objects, use methods(class="polynomial") Output: [1] as.character.polynomial* as.function.polynomial* coef.polynomial* [4] deriv.polynomial* GCD.polynomial* integral.polynomial* [7] LCM.polynomial* lines.polynomial* Math.polynomial* [10] Ops.polynomial* plot.polynomial* points.polynomial* [13] predict.polynomial* print.polynomial* solve.polynomial* [16] summary.polynomial* Summary.polynomial* -- Karl Ove Hufthammer ______________________________________________ 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.