RE: Extracting polynomial coef
- To: mathgroup@smc.vnet.net
- Subject: [mg11548] RE: [mg11464] Extracting polynomial coef
- From: Ersek_Ted%PAX1A@mr.nawcad.navy.mil
- Date: Sat, 14 Mar 1998 13:56:02 -0500
Tom Bell wrote:
|
|I have a very long polynomial that's a function of four variables, a,
b, |c, d. I would like Mathematica to (1) tell me what combinations of
a, |b, c, and d are in my polynomial, and (2) tell me what the
coefficients |are for each of the variable terms. |
|For example, say I have constant terms r and q. My polynomial might
|look something like
|
|4 a^2 b^3 c + r q d^5 + a d^3 + q c^2 a^2 + r^2 a d^3 |
|I would like to have Mathematica output something like: |
|a^2 b^3 => 4
|d^5 => r q
|a d^3 => 1 + r^2
|c^2 a^2 => q
|
|The polynomial is long enough that it would be very time-consuming to
|search through and identify all the combinations of (a,b,c,d). |
|
Tom,
Use CoefficientList[ poly, list] as below.
In[1]:=
ply=4 a^2 b^3 c + r q d^5 + a d^3 + q c^2 a^2 + r^2 a d^3;
coeff=CoefficientList[ply,{a,b,c,d}];
Now the coefficient of (a^na)*(b^nb)*(c^nc)*(d^nd) is Part[coeff,
(na+1),(nb+1),(nc+1),(nd+1)] For example I get the coefficient of
(a)(d^3) in the line below.
In[2]:=
Part[coeff, 2,1,1,4]
Out[2]=
1 + r^2
However in the next line the variables in CoeficientList[_,_] are in a
different order.
In[3]:=
new=CoefficientList[ply, {c,b,a,d}];
Now the coefficient of (a^na)(b^nb)(c^nc)(d^nd) is Part[coeff,
(nc+1),(nb+1),(na+1),(nd+1)] Again I get the coefficient of (a)(d^3) in
the line below.
In[4]:=
Part[new, 1,1,2,4]
Out[4]=
1 + r^2
I hope that takes care of it.
I couldn't find a place where the documentation explains how the result
is arranged when a list of variables are used. Because of that it
took a while to figure out. I sure wish details like this were better
documented.
Ted Ersek