[Date Index]
[Thread Index]
[Author Index]
Final comments on CoefficientList
*To*: mathgroup at smc.vnet.net
*Subject*: [mg2516] Final comments on CoefficientList
*From*: sherod at boussinesq.Colorado.EDU (Scott Herod)
*Date*: Wed, 15 Nov 1995 02:01:53 -0500
*Organization*: University of Colorado at Boulder
I'm pretty sure that CoefficientList has a bug in it. The simplest
example is
In[1]:= CoefficientList[0,x]
Out[1]= {}
But,
In[2]:= PolynomialQ[0,x]
Out[2]= True
This causes more problems when you try to create the list of coefficients
of a polynomial in multiple variables.
In[4]:= CoefficientList[ x y + x y^2, {y,x}]
Out[4]= {{}, {0, 1}, {0, 1}}
In[5]:= CoefficientList[x y + x y^2, {x,y}]
Out[5]= {{}, {0, 1, 1}}
Below are two functions which (I think) act correctly. Neither makes use
of caching as discussed by David Wagner in the most recent Mathematica
Journal but such could be added easily. I would appreciate comments on
improvements of these because I need to run them MANY times.
myCoefList[eqn_, x_Symbol] := myCoefList[eqn,{x}];
myCoefList[{eqn_}, x__] := myCoefList[eqn, x];
myCoefList[{eqn1_, eqn2__}, x__] :=
{myCoefList[eqn1, x], myCoefList[{eqn2}, x]};
myCoefList[eqn_, {x_}] :=
Table[Coefficient[eqn,x,i], {i,0, Max[Exponent[eqn, x],0]}];
myCoefList[eqn_, {x_, y__}] :=
Table[Coefficient[myCoefList[eqn,y],x,i],
{i,0,Max[Exponent[eqn,x],0]}];
myCoefList2[eqn_, var_] := Module[{coef, spam, a, b, c},
myCoefList::polynomial = "The equation is not a polynomial
in the variables";
coef[spam_, {a_, b_}] := Coefficient[spam, a, b];
coef[spam_, {a_, b_}, c__] := Coefficient[coef[spam, c], a, b];
If[PolynomialQ[eqn, var],
Array[
coef[eqn, Inner[List, var, List[##], Sequence]] &,
(Exponent[eqn,#] + 1 &) /@ var, 0]
,
Message[myCoefList::polynomial];
]
]
Scott A. Herod
Applied Mathematics
University of Colorado, Boulder
Prev by Date:
**pRe: Writing big files with Mathematica**
Next by Date:
**Problems with high-dimensional lists**
Previous by thread:
**Final comments on CoefficientList**
Next by thread:
**Re: Final comments on CoefficientList**
| |