[R] how can I get the coefficients of x^0, x^1, x^2, . , x^6 from expansion of (1+x+x^2)^3

james.holtman@convergys.com james.holtman at convergys.com
Fri Dec 3 21:43:43 CET 2004





Use the 'polynom' library:

> p <- as.polynomial(c(1,1,1))
> p
1 + x + x^2
> p^3
1 + 3*x + 6*x^2 + 7*x^3 + 6*x^4 + 3*x^5 + x^6
 > unclass(p^3)
[1] 1 3 6 7 6 3 1
>
__________________________________________________________
James Holtman        "What is the problem you are trying to solve?"
Executive Technical Consultant  --  Office of Technology, Convergys
james.holtman at convergys.com
+1 (513) 723-2929


                                                                                                                                           
                      "Peter Yang"                                                                                                         
                      <peterwyang at gmail.com        To:       <r-help at stat.math.ethz.ch>                                                    
                      >                            cc:                                                                                     
                      Sent by:                     Subject:  [R] how can I get the coefficients of x^0, x^1, x^2, . ,    x^6 from          
                      r-help-bounces at stat.m         expansion of (1+x+x^2)^3                                                               
                      ath.ethz.ch                                                                                                          
                                                                                                                                           
                                                                                                                                           
                      12/03/2004 14:56                                                                                                     
                                                                                                                                           
                                                                                                                                           




Hi,



I would like to get the coefficients of x^0, x^1, x^2,  . , x^6 from
expansion of (1+x+x^2)^3.

The result should be 1, 3, 6, 7, 6, 3, 1;



How can I calculate in R?



You help will be greatly appreciated.



Peter






             [[alternative HTML version deleted]]

______________________________________________
R-help at 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




More information about the R-help mailing list