MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Extracting polynomial coefficients?



Try this:
p=4 a^2 b^3 c + r q d^5 + a d^3 + q c^2 a^2 + r^2 a d^3
allVariables=Variables[p]
myConstants={r,q}
myVariables=Complement[allVariables,myConstants] FullForm[p](*this to
explain the following replacement rules*)
np=p/.Flatten[{Plus->List,Times[y_?IntegerQ,z_]->z,Map[(#->1)&,myConstants]}]
Map[{#,Coefficient[p,#]}&,np]

Hope this helps,


----------------------------------------------- Jean-Marie THOMAS
Conseil et Audit en Ingenierie de Calcul www.cybercable.tm.fr/~jmthomas
------------------------------------------------


-----Message d'origine-----
De:	Thomas Bell [SMTP:tombell@leland.Stanford.EDU] Date:	jeudi 12 mars
1998 07:35
A:	mathgroup@smc.vnet.net
Objet:	[mg11464] Extracting polynomial coefficients?

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).

Any help appreciated.  Thanks.

 -------------------------------------------------------------- Thomas
(Tom) Bell		Gravity Probe-B, H.E.P.L. tombell@stanford.edu    	Stanford
University 136D Escondido Village		Stanford, CA 94305-4085 Stanford, CA
94305		650/725-6378 (o) 650/497-4230 (h)		650/725-8312 (fax)




  • Prev by Date: Re: Solving Overdetermined Systems
  • Next by Date: Odd behaviour in Mathematica 3.0.1
  • Prev by thread: Re: Extracting polynomial coefficients?
  • Next by thread: Re: Extracting polynomial coefficients?