Re: Extract coefficients of a trig polynomial

• To: mathgroup at smc.vnet.net
• Subject: [mg126139] Re: Extract coefficients of a trig polynomial
• From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
• Date: Fri, 20 Apr 2012 07:47:23 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com

```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]]))/1536}, {0, 0,
0, 0, 0, 0,
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, -(3/128) \[Epsilon]^2 \[Rho] (-4 (\[Rho] +
2 \[Epsilon] \[Rho]) BesselJ[
0, \[Rho]] + (-8 + \[Epsilon] (-8 + \[Rho]^2)) BesselJ[
1, \[Rho]]), 0,
5/512 \[Epsilon]^3 \[Rho] (-8 \[Rho] BesselJ[
0, \[Rho]] + (-8 + \[Rho]^2) BesselJ[1, \[Rho]]), 0, 0}, {0, 0,
0, 0, 0, 0,
0}, {1/256 \[Epsilon]^2 \[Rho] (-4 (\[Rho] +
2 \[Epsilon] \[Rho]) BesselJ[
0, \[Rho]] + (-8 + \[Epsilon] (-8 + \[Rho]^2)) BesselJ[
1, \[Rho]]),
0, -(5/512) \[Epsilon]^3 \[Rho] (-8 \[Rho] BesselJ[
0, \[Rho]] + (-8 + \[Rho]^2) BesselJ[1, \[Rho]]), 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0,
0}, {(\[Epsilon]^3 \[Rho] (-8 \[Rho] BesselJ[
0, \[Rho]] + (-8 + \[Rho]^2) BesselJ[1, \[Rho]]))/1536, 0, 0,
0, 0, 0, 0}}

Hope it helps. Have fun, Alexei

Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch at iee.lu

```

• Prev by Date: Re: Extract coefficients of a trig polynomial
• Next by Date: Re: How to change graph options?
• Previous by thread: Re: Extract coefficients of a trig polynomial
• Next by thread: Re: Extract coefficients of a trig polynomial