       Re: extracting powers and coefficients from a polynomial

• To: mathgroup at smc.vnet.net
• Subject: [mg49134] Re: extracting powers and coefficients from a polynomial
• From: Paul Abbott <paul at physics.uwa.edu.au>
• Date: Fri, 2 Jul 2004 02:01:44 -0400 (EDT)
• Organization: The University of Western Australia
• References: <cbrcau\$iqc\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```In article <cbrcau\$iqc\$1 at smc.vnet.net>,
"AngleWyrm" <no_spam_anglewyrm at hotmail.com> 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
> ....

Pattern-matching is an easy way of doing this:

poly = Expand[(Sum[x^i, {i, 6}])^3]

List @@ poly /. c_. x^n_. -> {n, c}

Cheers,
Paul

--
Paul Abbott                                   Phone: +61 8 9380 2734
School of Physics, M013                         Fax: +61 8 9380 1014
The University of Western Australia      (CRICOS Provider No 00126G)
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au
AUSTRALIA                            http://physics.uwa.edu.au/~paul

```

• Prev by Date: Re: Troubles with Integrating certain functions in 5.0
• Next by Date: Off[] won't always eliminate the message
• Previous by thread: Re: DSolve question
• Next by thread: Off[] won't always eliminate the message