MathGroup Archive 1997

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

Search the Archive

Re: Collect, Coefficient, and non-integer exponents

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8763] Re: [mg8733] Collect, Coefficient, and non-integer exponents
  • From: Olivier Gerard <jacquesg at pratique.fr>
  • Date: Sun, 21 Sep 1997 20:51:07 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Sergio,

That's true, Coefficient and CoefficientList seems to be at ease
only with integer coefficients. One reason for that (in Coefficient
List) is certainly that if you allow say, rationals, you must make
a lot of decisions about how sorting the exponents and which one
you include as being with zero coefficients.

There is perhaps a standard way of dealing with that but I did
not found any, so in order to help you, I just programmed a
little hack. Here is an example (similar to yours) and the code:

In[26]:=
test = bdbd + 5x + x^7 + Expand[Sum[(a*n+b*n-c)*x^(n+12/100 n)y^k,{n,1,4}]]

Out[26]=
bdbd + 5 x + x^7 + a x^(28/25) y^k + b x^(28/25) y^k -
    c x^(28/25) y^k + 2 a x^(56/25) y^k +
    2 b x^(56/25) y^k - c x^(56/25) y^k +
    3 a x^(84/25) y^k + 3 b x^(84/25) y^k -
    c x^(84/25) y^k + 4 a x^(112/25) y^k +
    4 b x^(112/25) y^k - c x^(112/25) y^k

In[27]:=GetPolyCoeff[ Poly_Plus, x_Symbol]:=
		 Module[ {hh},
    Map[{Plus@@Cases[hh,List[cf_, #]-> cf],#}&,
      Union[Last[
          Transpose[
            hh=Cases[
                Map[(# /. {
                          Times[ cf___,Power[x,r_]]| Power[x, r_]:>{Times[cf],
                              r}, Times[cf___,x]:>{Times[cf],1},

		cf:_:>{cf,0}/;FreeQ[cf,x]})&,
List@@Poly,{1}],_List,{1}]]]]]]


In[28]:=
GetPolyCoeff[test,x]

Out[28]=
{{bdbd, 0}, {5, 1}, {a y^k + b y^k - c y^k, 28/25}, {
      2 a y^k + 2 b y^k - c y^k, 56/25}, {
      3 a y^k + 3 b y^k - c y^k, 84/25}, {
      4 a y^k + 4 b y^k - c y^k, 112/25}, {1, 7}}


As you can see it works quite well with your example,
giving an ordered list of lists containing the coefficient and the exponent.
Other features: it filters out Functions depending on x put not
of a polynomial form such as Sin[x], or WhatEverYouCallIt[x].

If what you want is only the coefficient for a particular exponent,
you can simplify the routine a lot, or just Use a Select or Cases
on the result of this one.

It is not intended as a general purpose routine at all.
It does not work for an isolated Power or for any NON EXPANDED polynomial.
It works only for one variable at a time (and it ought to be a symbol).
It does a lot of crude assumptions on the form of the input but something
smarter would need more work than I can currently devote to this issue.
(Perhaps we can make up a little group with people of the list
interested in such a routine to build a complete implementation
and then post it to mathgroup and mathsource. A few weeks ago
we did an improvised contest on optimizing a PaddedThread routine
and it was very enriching, I believe).


A final word of advice. When you are dealing with non integer
parameters, try to enter them as much as possible as fractions,
not with a "." which would be considered a limited precision real.
It could undermine the precision or even the possibility of all
the computations you make later.


Olivier


At 04:28 +0200 97.09.21, Sergio Rojas wrote:
> (**
> 	Hi folks,
>
>         Assume that for fun one want to deal with an expression containing
>         non-integer powers of a certain variable x. Take as an illustration
>   	the following expression;
> 								     ******)
> expr = Expand[Sum[(a*n +b*n -c)*x^(n+0.12/n),{n,1,4}]];
>
> (**
>   	One knows in advance that a power of x is, for example, 1.12 and
>      	we want to know its coefficient. Apparently Coefficient and Collect
>         work only with integers. Is there a way to deal with this situation?
>
> Salut,
>
> Rojas
> E-mail: sergio at scisun.sci.ccny.cuny.edu
>
> PS.
>    I am using Mathematica:
> In[37]:= $Version
> Out[37]= DEC OSF/1 Alpha 2.2 (September 9, 1994)
>
> 								     ******)
>






  • Prev by Date: Boundary Value Problem
  • Next by Date: Re: Q: Collect, Coefficient, and non-integer exponents
  • Previous by thread: Boundary Value Problem
  • Next by thread: Re: Collect, Coefficient, and non-integer exponents