[R] Coefficients of a factorized polynomial

From: Serguei Kaniovski <kaniovsk_at_wsr.ac.at>
Date: Mon 09 Oct 2006 - 06:42:42 GMT


Hi all,

starting from a vector "v[1:n]" I would like to compute the coefficients of the polynomial (1+x^v[1])*(1+x^v[2])*...*(1+x^v[n]). The following code works but is extremely slow for a large "n" due to, I believe, the polynomial being factorized. I wanted to try the package "polynom" command "unclass" but I could not figure out how to input a factorized polynomial. Can you please help?

Serguei

v<-c(1,1,2,3,4,6)

e<-parse(text=paste("(1+x^", v, sep="", collapse="*", ")"))

DD<-function(expr, name, order = 0) {

	if(order == 0)expr
	else DD(D(expr, name), name, order - 1)
}

sapply(0:18, function(i) eval(DD(e, "x", i), list(x=0)))/factorial(0:18)



R-help@stat.math.ethz.ch 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. Received on Mon Oct 09 16:45:10 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 09 Oct 2006 - 08:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.