Re: Getting the small parts right or wrong. Order and Collect
- To: mathgroup at smc.vnet.net
- Subject: [mg63658] Re: Getting the small parts right or wrong. Order and Collect
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Mon, 9 Jan 2006 04:48:39 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
On 1/8/06 at 3:32 AM, fateman at cs.berkeley.edu (Richard Fateman) wrote: >Putting the coefficients in an array is plausible, but Andrzej >other solution, which is >1 + Plus @@ Table[Coefficient[(1 + x + y)^3, x^i]*x^i, {i, 1, 3}] >is wrong because it results in answers in the order 1, x^3, x^2, x. More importantly, this solution omits the terms with y but not x. That is In[7]:= (1 + Plus@@Table[Coefficient[(1+x+y)^3, x^i] x^i, {i, 1, 3}]])//Simplify Out[7]=x^3 + 3*(y + 1)*x^2 + 3*(y + 1)^2*x + 1 is clearly not (1+x+y)^3 >And of course picking out the coefficient of "1". >Along those lines it is better to do ... >Table[Coefficient[(1+x+y)^3,x,i] ,{i,0,3}] where i can also be 0. >And the table keeps the coefficients from being randomly sorted. And this will not work either since Coefficient will correctly point out x^0 which evaluates to 1 is not a valid variable. To get a list of the coefficients you should use CoefficientList, i.e., In[13]:=CoefficientList[(1 + x + y)^3, x] Out[13]= {y^3 + 3*y^2 + 3*y + 1, 3*y^2 + 6*y + 3, 3*y + 3, 1} which can be used with Table to generate the desired form, i.e., CoefficientList[(1 + x + y)^3, x].Table[x^n, {n,0,3}] -- To reply via email subtract one hundred and four