Re: extracting powers and coefficients from a polynomial
- To: mathgroup at smc.vnet.net
- Subject: [mg49064] Re: [mg49040] extracting powers and coefficients from a polynomial
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Wed, 30 Jun 2004 05:34:11 -0400 (EDT)
- References: <200406290850.EAA18783@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 29 Jun 2004, at 17:50, AngleWyrm wrote:
> I have made a formula that produces a polynomial expansion, and I wish
> to
> extract the powers and coefficients into a list.
>
> Expand[(Sum[x^i, {i, 6}])^3]
> 1x^3 + 3x^4 + 6x^5 + 10x^6 + 15x^7 + 21x^8 + 25x^9 + 27x^10 + 27x^11
> + 25x^12
> + 21x^13 + 15x^14 + 10x^15 + 6x^16 + 3x^17 + 1x^18
>
> How do I make a table of the powers and coefficents?
> 3, 1
> 4, 3
> 5, 6
> 6, 10
> ....
>
> --
> AngleWyrm
> The C++ hat random selection container:
> http://home.comcast.net/~anglewyrm/hat.html
>
>
>
If you do not mind using an undocumented function then probably the
simplest way is:
Reverse[Flatten/@First[Internal`DistributedTermsList[f,x]]]
{{3,1},{4,3},{5,6},{6,10},{7,15},{8,21},{9,25},{10,27},{11,27},{12,25},{
13,21},{14,15},{15,10},{16,6},{17,3},{18,1}}
Or you can use CoefficientList as follows:
With[{l=CoefficientList[f,x]},Transpose[{Range[0,Length[l]-1],l}]]
{{0,0},{1,0},{2,0},{3,1},{4,3},{5,6},{6,10},{7,15},{8,21},{9,25},{10,27}
,{
11,27},{12,25},{13,21},{14,15},{15,10},{16,6},{17,3},{18,1}}
Note that the first three terms given above have coefficient 0. One
could drop all leading 0 coefficient terms like this:
Flatten[Rest[Split[With[{
l=CoefficientList[f,x]},Transpose[{Range[0,Length[l]-1],l}]],#1[[
2]]==#2[[2]]&]],1]
{{3,1},{4,3},{
5,6},{6,10},{7,15},{8,21},{9,25},{10,27},{11,27},{12,25},{13,21},{
14,15},{15,10},{16,6},{17,3},{18,1}}
Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/
- References:
- extracting powers and coefficients from a polynomial
- From: "AngleWyrm" <no_spam_anglewyrm@hotmail.com>
- extracting powers and coefficients from a polynomial