Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

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

Search the Archive

Re: Extract coefficients of a trig polynomial

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126160] Re: Extract coefficients of a trig polynomial
  • From: Sam Takoy <sam.takoy at yahoo.com>
  • Date: Sun, 22 Apr 2012 06:04:57 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <7BB0E96E72E84E41B24A1FF8ED13F5E6299A6B5B61@IE2RD2XVS581.red002.local>
  • Reply-to: Sam Takoy <sam.takoy at yahoo.com>

Thank you, that's very nice.


________________________________
From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
To: "mathgroup at smc.vnet.net" <mathgroup at smc.vnet.net> 
Cc: "sam.takoy at yahoo.com" <sam.takoy at yahoo.com> 
Sent: Friday, April 20, 2012 4:59 AM
Subject: [mg126160] Re: Extract coefficients of a trig polynomial
 
Hi,

Suppose I have an expression that is a trigonometric polynomial in
theta. Is there a way to neatly pick out the coefficients of the
polynomial. I find that FourierCoefficient takes quite a bit of time,
probably because it does a lot of integrations. My coefficients are
very complicated expressions but do not depend on theta.

Many thanks in advance,

Sam

Hi, 
This is your expression:

expr = (1/1536) (1536 BesselJ[0, \[Rho]] - 
     72 \[Epsilon]^2 \[Rho]^2 BesselJ[0, \[Rho]] - 
     80 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] - 
     384 \[Epsilon] \[Rho] BesselJ[1, \[Rho]] - 
     144 \[Epsilon]^2 \[Rho] BesselJ[1, \[Rho]] - 
     80 \[Epsilon]^3 \[Rho] BesselJ[1, \[Rho]] + 
     10 \[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]] - 
     96 \[Epsilon]^2 \[Rho]^2 BesselJ[0, \[Rho]] Cos[2 \[Theta]] - 
     120 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] Cos[2 \[Theta]] - 
     384 \[Epsilon] \[Rho] BesselJ[1, \[Rho]] Cos[2 \[Theta]] - 
     192 \[Epsilon]^2 \[Rho] BesselJ[1, \[Rho]] Cos[2 \[Theta]] - 
     120 \[Epsilon]^3 \[Rho] BesselJ[1, \[Rho]] Cos[2 \[Theta]] + 
     15 \[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]] Cos[2 \[Theta]] - 
     24 \[Epsilon]^2 \[Rho]^2 BesselJ[0, \[Rho]] Cos[4 \[Theta]] - 
     48 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] Cos[4 \[Theta]] - 
     48 \[Epsilon]^2 \[Rho] BesselJ[1, \[Rho]] Cos[4 \[Theta]] - 
     48 \[Epsilon]^3 \[Rho] BesselJ[1, \[Rho]] Cos[4 \[Theta]] + 
     6 \[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]] Cos[4 \[Theta]] - 
     8 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] Cos[6 \[Theta]] - 
     8 \[Epsilon]^3 \[Rho] BesselJ[1, \[Rho]] Cos[
       6 \[Theta]] + \[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]] Cos[
       6 \[Theta]]);

One can expand trigonometric expressions and collect the results in polynomial of Cos[\[Theta]]^n and Sin[\[Theta]]^n up to n=6.

expr2 = TrigExpand[expr];
expr3 = Collect[expr2, _Sin && _Cos]

BesselJ[0, \[Rho]] - 3/64 \[Epsilon]^2 \[Rho]^2 BesselJ[0, \[Rho]] - 
5/96 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] - 
1/4 \[Epsilon] \[Rho] BesselJ[1, \[Rho]] - 
3/32 \[Epsilon]^2 \[Rho] BesselJ[1, \[Rho]] - 
5/96 \[Epsilon]^3 \[Rho] BesselJ[1, \[Rho]] + 
5/768 \[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]] - 
1/16 \[Epsilon]^2 \[Rho]^2 BesselJ[0, \[Rho]] Cos[\[Theta]]^2 - 
5/64 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] Cos[\[Theta]]^2 - 
1/4 \[Epsilon] \[Rho] BesselJ[1, \[Rho]] Cos[\[Theta]]^2 - 
1/8 \[Epsilon]^2 \[Rho] BesselJ[1, \[Rho]] Cos[\[Theta]]^2 - 
5/64 \[Epsilon]^3 \[Rho] BesselJ[1, \[Rho]] Cos[\[Theta]]^2 + 
5/512 \[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]] Cos[\[Theta]]^2 - 
1/64 \[Epsilon]^2 \[Rho]^2 BesselJ[0, \[Rho]] Cos[\[Theta]]^4 - 
1/32 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] Cos[\[Theta]]^4 - 
1/32 \[Epsilon]^2 \[Rho] BesselJ[1, \[Rho]] Cos[\[Theta]]^4 - 
1/32 \[Epsilon]^3 \[Rho] BesselJ[1, \[Rho]] Cos[\[Theta]]^4 + 
1/256 \[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]] Cos[\[Theta]]^4 - 
1/192 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] Cos[\[Theta]]^6 - 
1/192 \[Epsilon]^3 \[Rho] BesselJ[
   1, \[Rho]] Cos[\[Theta]]^6 + (\[Epsilon]^3 \[Rho]^3 BesselJ[
   1, \[Rho]] Cos[\[Theta]]^6)/1536 + 
1/16 \[Epsilon]^2 \[Rho]^2 BesselJ[0, \[Rho]] Sin[\[Theta]]^2 + 
5/64 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] Sin[\[Theta]]^2 + 
1/4 \[Epsilon] \[Rho] BesselJ[1, \[Rho]] Sin[\[Theta]]^2 + 
1/8 \[Epsilon]^2 \[Rho] BesselJ[1, \[Rho]] Sin[\[Theta]]^2 + 
5/64 \[Epsilon]^3 \[Rho] BesselJ[1, \[Rho]] Sin[\[Theta]]^2 - 
5/512 \[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]] Sin[\[Theta]]^2 + 
3/32 \[Epsilon]^2 \[Rho]^2 BesselJ[
   0, \[Rho]] Cos[\[Theta]]^2 Sin[\[Theta]]^2 + 
3/16 \[Epsilon]^3 \[Rho]^2 BesselJ[
   0, \[Rho]] Cos[\[Theta]]^2 Sin[\[Theta]]^2 + 
3/16 \[Epsilon]^2 \[Rho] BesselJ[
   1, \[Rho]] Cos[\[Theta]]^2 Sin[\[Theta]]^2 + 
3/16 \[Epsilon]^3 \[Rho] BesselJ[
   1, \[Rho]] Cos[\[Theta]]^2 Sin[\[Theta]]^2 - 
3/128 \[Epsilon]^3 \[Rho]^3 BesselJ[
   1, \[Rho]] Cos[\[Theta]]^2 Sin[\[Theta]]^2 + 
5/64 \[Epsilon]^3 \[Rho]^2 BesselJ[
   0, \[Rho]] Cos[\[Theta]]^4 Sin[\[Theta]]^2 + 
5/64 \[Epsilon]^3 \[Rho] BesselJ[
   1, \[Rho]] Cos[\[Theta]]^4 Sin[\[Theta]]^2 - 
5/512 \[Epsilon]^3 \[Rho]^3 BesselJ[
   1, \[Rho]] Cos[\[Theta]]^4 Sin[\[Theta]]^2 - 
1/64 \[Epsilon]^2 \[Rho]^2 BesselJ[0, \[Rho]] Sin[\[Theta]]^4 - 
1/32 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] Sin[\[Theta]]^4 - 
1/32 \[Epsilon]^2 \[Rho] BesselJ[1, \[Rho]] Sin[\[Theta]]^4 - 
1/32 \[Epsilon]^3 \[Rho] BesselJ[1, \[Rho]] Sin[\[Theta]]^4 + 
1/256 \[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]] Sin[\[Theta]]^4 - 
5/64 \[Epsilon]^3 \[Rho]^2 BesselJ[
   0, \[Rho]] Cos[\[Theta]]^2 Sin[\[Theta]]^4 - 
5/64 \[Epsilon]^3 \[Rho] BesselJ[
   1, \[Rho]] Cos[\[Theta]]^2 Sin[\[Theta]]^4 + 
5/512 \[Epsilon]^3 \[Rho]^3 BesselJ[
   1, \[Rho]] Cos[\[Theta]]^2 Sin[\[Theta]]^4 + 
1/192 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] Sin[\[Theta]]^6 + 
1/192 \[Epsilon]^3 \[Rho] BesselJ[
   1, \[Rho]] Sin[\[Theta]]^6 - (\[Epsilon]^3 \[Rho]^3 BesselJ[
   1, \[Rho]] Sin[\[Theta]]^6)/1536

Now you can find the coefficients at any thinkable power of Cos[\[Theta]]^n*Sin[\[Theta]]^m. For example, here is a list of coefficients at Cos[\[Theta]]^n (n=0,1,...6):

expr4 = Coefficient[expr3, Cos[\[Theta]], #] & /@ 
   Table[i, {i, 0, 6}] /. a_*Sin[\[Theta]]^n_ -> 0

{BesselJ[0, \[Rho]] - 3/64 \[Epsilon]^2 \[Rho]^2 BesselJ[0, \[Rho]] - 
  5/96 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] - 
  1/4 \[Epsilon] \[Rho] BesselJ[1, \[Rho]] - 
  3/32 \[Epsilon]^2 \[Rho] BesselJ[1, \[Rho]] - 
  5/96 \[Epsilon]^3 \[Rho] BesselJ[1, \[Rho]] + 
  5/768 \[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]], 0, -(1/
    16) \[Epsilon]^2 \[Rho]^2 BesselJ[0, \[Rho]] - 
  5/64 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] - 
  1/4 \[Epsilon] \[Rho] BesselJ[1, \[Rho]] - 
  1/8 \[Epsilon]^2 \[Rho] BesselJ[1, \[Rho]] - 
  5/64 \[Epsilon]^3 \[Rho] BesselJ[1, \[Rho]] + 
  5/512 \[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]], 0, -(1/
    64) \[Epsilon]^2 \[Rho]^2 BesselJ[0, \[Rho]] - 
  1/32 \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] - 
  1/32 \[Epsilon]^2 \[Rho] BesselJ[1, \[Rho]] - 
  1/32 \[Epsilon]^3 \[Rho] BesselJ[1, \[Rho]] + 
  1/256 \[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]], 0, -(1/
    192) \[Epsilon]^3 \[Rho]^2 BesselJ[0, \[Rho]] - 
  1/192 \[Epsilon]^3 \[Rho] BesselJ[
    1, \[Rho]] + (\[Epsilon]^3 \[Rho]^3 BesselJ[1, \[Rho]])/1536}

Analogously you can find other terms. Alternatively you could establish a CoefficientList. Here below I build this list and simplify each its term:

coeffLst = 
Simplify[#, {\[Epsilon] > 0, \[Rho] > 0}] & /@ 
  CoefficientList[expr3, {Cos[\[Theta]], Sin[\[Theta]]}]

{{1/768 (-4 (-192 + 9 \[Epsilon]^2 \[Rho]^2 + 
        10 \[Epsilon]^3 \[Rho]^2) BesselJ[
       0, \[Rho]] + \[Epsilon] \[Rho] (-192 - 72 \[Epsilon] + 
        5 \[Epsilon]^2 (-8 + \[Rho]^2)) BesselJ[1, \[Rho]]), 0, 
  1/512 \[Epsilon] \[Rho] (8 \[Epsilon] (4 + 
        5 \[Epsilon]) \[Rho] BesselJ[
       0, \[Rho]] + (128 + 64 \[Epsilon] - 
        5 \[Epsilon]^2 (-8 + \[Rho]^2)) BesselJ[1, \[Rho]]), 0, 
  1/256 \[Epsilon]^2 \[Rho] (-4 (\[Rho] + 
        2 \[Epsilon] \[Rho]) BesselJ[
       0, \[Rho]] + (-8 + \[Epsilon] (-8 + \[Rho]^2)) BesselJ[
       1, \[Rho]]), 
  0, (\[Epsilon]^3 \[Rho] (8 \[Rho] BesselJ[
       0, \[Rho]] - (-8 + \[Rho]^2) BesselJ[1, \[Rho]]))/


  • Prev by Date: Re: LogLogPlot encounters Infinite expression
  • Next by Date: Re: Adding to a plot
  • Previous by thread: Re: Extract coefficients of a trig polynomial
  • Next by thread: numerical solution to a set of equations with hypergeometric function