MathGroup Archive 2008

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

Search the Archive

Re: Coefficient[ ] quirks

  • To: mathgroup at
  • Subject: [mg93325] Re: [mg93310] Coefficient[ ] quirks
  • From: Andrzej Kozlowski <akoz at>
  • Date: Tue, 4 Nov 2008 06:15:54 -0500 (EST)
  • References: <> <>

On 3 Nov 2008, at 20:34, Andrzej Kozlowski wrote:

> On 3 Nov 2008, at 19:28, AES wrote:
>> If you have a function  f = a + b (z-c)^2 and want to extract out the
>> powers of the "form" (z-c), you can use either Coefficient[f, (z- 
>> c), n]
>> or Coefficient[f, (z-c)^2, n].  The first one gives you {a, 0, b} for
>> the first three coefficients, while the second one gives you {a, b,  
>> 0},
>> both of these of course being entirely correct.
>> Suppose however that you add a denominator to the function, e.g.
>> f = (a + b (z-c)^2 )/d.  Then the first approach (looking for  
>> powers of
>> (z-c)) no longer gives you the information you're seeking, but  
>> instead
>> stuffs the entire f into the first position, i.e. {f, 0, 0} --  
>> which at
>> least doesn't throw away any information about f.
>> The second approach (looking for powers of (z-c)^2) still works fine
>> even with a denominator added, however, and gives you {a/d, b/d, 0}.
>> If out of restless curiosity, you then expand out the square of (z-c)
>> into either of the forms  f = (a + b (z^2 - 2 c z + c^2) or
>> f = (a + b z^2 - 2 b c z + + b c^2), with or without the denominator,
>> but still seek powers of (z-c) (which are no longer explicitly  
>> present),
>> the first approach continues to give you {f, 0, 0}, which it can be
>> argued is entirely correct, since there is no longer any explicit  
>> power
>> of (z-c) in f.
>> The second approach, however, now gives you either {a, 0, 0} or {a/ 
>> d, 0,
>> 0}, which in a certain sense is arguably correct for the first or n=0
>> term -- any powers of z or c have apparently been chopped off, even
>> though you asked Coefficient to look only for powers of (z-c).
>> The only problem is that they seem to have been thrown out totally,
>> beyond recovery.  You could write
>>  f = Sum[Coefficient[f, (z-c), n] * (z-c)^n, {n,0,Infinity}]
>> for f with or without denominator, and never get all your function  
>> back.
>> It all seems rather quirky . . .
> Because it is not the way to do this at all...
> There are a number possible approaches but only one that is  
> completely reliable (and very standard in this sort of situation,  
> not just in Mathematica) is :
> f = (a + b (z^2 - 2 c z + c^2))
> SeriesCoefficient[f + O[z, c]^10, 2]
> b
> This will work no matter how you express your f.
> Andrzej Kozlowski

Actually, there is a slightly better way, based on the same idea.  
Above I expanded f as a Taylor series about c wit remainder of order  
10, which I chose essentially arbitrarily , making sure that it is  
large enough. But this is not needed, Mathematica is cleverer than  
that. All you need is

SeriesCoefficient[f, {z, c, 2}]

In other words, one does not need to expand f to some fixed order, it  
is enough to tell Mathematica that we want the Coefficient of the term  
of degree 2 and Mathematica will do the expanding itself. This is much  
more convenient and, as far as I know, the best way to deal with this  

Andrzej Kozlowski

  • Prev by Date: Re: Coefficient[ ] quirks
  • Next by Date: Re: Trinomial decics x^10+ax+b = 0; Help with Mathematica code
  • Previous by thread: Re: Coefficient[ ] quirks
  • Next by thread: Mathematica Help Urgent (Very New Beginner)