From: Peter Yang <[EMAIL PROTECTED]>
>I would like to get the coefficients of x^0, x^1, x^2, . , x^6 from
>expansion of (1+x+x^2)^3.
# modification of DD in example(D) to support 0th derivative
DD <- function(expr,name, order = 0) {
if(order == 0)
expr
else DD(D(expr, name), name, order - 1)
}
# take symbolic derivatives, evaluate at 0 and divide by factorial n
sapply(0:6, function(i) eval(DD(e,"x",i),list(x=0)))/factorial(0:6)
By the way, e in the above is your expression, in this case:
e <- expression((1+x+x^2)^3)
______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html