1
$\begingroup$

I want to organize my expressions as a fourier series of sin and cos. That is, I want them to be of the form $$a_0 + a_1 \cos[ w t] + b_1 \sin[ w t] + a_2 \cos[2 w t] + b_2 \sin[2 w t] + ... $$

Unfortunately, the expressions are messy. Terms in the expressions contain products and sums of time-sinusoids and other sinusoids, such as $$ (\sin[3 w t+ \text{expr}]^2 +\cos[ \text{expr}_2])^3 \cos[ \text{expr}_3] $$

What I tried

I would like to use organize them into terms of varying frequencies (e.g. Sin[n w t] , where n is an integer)

  • I tried Collect[%, {Cos[_*w*t], Sin[_*w*t]}, Together], however, this doesn't work because I have products of time sinusoides that I need to trig reduce.

  • I tried using trig reduce, but that mixes the time-sinusoids with the other sinusoids.

  • I tried a variety of permutations involving trig reduce, trig expand, expand, and Collect[%, {Cos[w*t]^_, Sin[_*w*t]^_}, Together], to no avail.

  • I tried explicitly defining rules to apply before applying Collect, such as

trigNoPower = {
   Cos[ n_]^a_ ?(IntegerQ[#] && # > 1 &) ->   
    Cos[  n]^(a - 2)   * (1 + Cos[2 n])/2 ,
   Sin[ n_]^a_ ?(IntegerQ[#] && # > 1 &) ->   
    Cos[  n]^(a - 2)   * (1 - Cos[2 n])/2 ,
   
   Sin[a_] Sin[b_] -> (Cos[a - b] - Cos[a + b])/2,
   Cos[a_] Cos[b_] -> (Cos[a - b] + Cos[a + b])/2,
   Sin[a_] Cos[b_] -> (Sin[a + b] + Sin[a - b])/2,
   Cos[a_] Sin[b_] -> (Sin[a + b] - Sin[a - b])/2
   };
(*Example Usage*)
(4 BesselJ[2, \[Phi]m]^2 Cos[2 t w]^2 Sin[\[Delta]m] Sin[\[Delta]p])/(
  rm rp)  //. trigNoPower;
Collect[%, {Cos[_*w*t], Sin[_*w*t]}, HoldForm@*Evaluate@*Simplify] 

However no combination of the above worked completely for my sample expressions below. What should I do instead?

Sample Expressions

For reference, one of my expressions is:

hopefullyFourier = 4 ξ^2 ((BesselJ[0, ϕm] + 
      2 BesselJ[2, ϕm] Cos[2 t w])^2 Sin[δp]^2 + 
   4 βq^2 Cos[ϕmag]^2 (BesselJ[1, ϕm] Sin[t w] + 
      BesselJ[3, ϕm] Sin[
        3 t w])^2 Sin[θmag]^4 Sin[ϕmag]^2)

or expanded

In[1]:= hopefullyFourier //Expand
Out[1] = 4 ξ^2 BesselJ[0, ϕm]^2 Sin[δp]^2 + 
 16 ξ^2 BesselJ[0, ϕm] BesselJ[2, ϕm] Cos[
   2 t w] Sin[δp]^2 + 
 16 ξ^2 BesselJ[2, ϕm]^2 Cos[2 t w]^2 Sin[δp]^2 + 
 16 βq^2 ξ^2 BesselJ[1, ϕm]^2 Cos[ϕmag]^2 Sin[
   t w]^2 Sin[θmag]^4 Sin[ϕmag]^2 + 
 32 βq^2 ξ^2 BesselJ[1, ϕm] BesselJ[
   3, ϕm] Cos[ϕmag]^2 Sin[t w] Sin[
   3 t w] Sin[θmag]^4 Sin[ϕmag]^2 + 
 16 βq^2 ξ^2 BesselJ[3, ϕm]^2 Cos[ϕmag]^2 Sin[
   3 t w]^2 Sin[θmag]^4 Sin[ϕmag]^2

And to give another taste, that includes how I generate a particular messy expression (i.e. hopefullyFourier2 below) from a Jacobi-Anger expansion

jacobiAnger[
   order_] = {Cos[z_*Sin[\[Theta]_]] -> 
    BesselJ[0, z] + 
     2 Sum[BesselJ[n, z] Cos[n \[Theta]], {n, 2, order, 2}],
   Sin[z_*Sin[\[Theta]_]] -> 
    2 Sum[BesselJ[n, z] Sin[n \[Theta]], {n, 1, order, 2}] 
   };


faradayIntensity = 1/(2 rm^2) + 1/(2 rp^2) + Cos[\[Delta]m - \[Delta]p]/(rm rp) + 
 Cos[2 \[Phi]m Sin[t w]]/(2 rm^2) + Cos[2 \[Phi]m Sin[t w]]/(2 rp^2) +
  Cos[\[Delta]m - \[Delta]p - 2 \[Phi]m Sin[t w]]/(2 rm rp) + 
 Cos[\[Delta]m - \[Delta]p + 2 \[Phi]m Sin[t w]]/(2 rm rp)
% // TrigExpand;
hopefullyFourier2 = % /. jacobiAnger[3];


% // Expand;
% //. trigNoPower; (* see the what I tried section for definition of this *)
Collect[%, {Cos[_*w*t], Sin[_*w*t]}, Hold@*Evaluate@*Simplify];


```
$\endgroup$

1 Answer 1

2
$\begingroup$

Try

expr=4 \[Xi]^2 ((BesselJ[0, \[Phi]m] + 2 BesselJ[2, \[Phi]m] Cos[2 t w])^2 Sin[\[Delta]p]^2 + 4 \[Beta]q^2 Cos[\[Phi]mag]^2 (BesselJ[1, \[Phi]m] Sin[t w] +BesselJ[3, \[Phi]m] Sin[3 t w])^2 Sin[\[Theta]mag]^4 Sin[\[Phi]mag]^2) // TrigExpand//Expand

Collect[expr , {Sin[Times[t, _ ]], Cos[Times[t, _ ]] }, Simplify]
$\endgroup$
5
  • $\begingroup$ This doesn't work quite right, because it gives me -2 \[Beta]q^2 \[Xi]^2 BesselJ[3, \[Phi]m]^2 Cos[ t w]^6 Sin[\[Theta]mag]^4 Sin[2 \[Phi]mag]^2 for my first term, which is not of the form I wanted (Sin[n w t] , where n is an integer) $\endgroup$
    – ions me
    Feb 19 at 3:51
  • $\begingroup$ So there's no surprises when you look back at this, I updated the wording of my question from saying I want terms of the form"Sin[n w t] , where n is an integer" , to the equivalent statement "I want to group terms into a Fourier series. " Also added another example that almost works .. but not quite. $\endgroup$
    – ions me
    Feb 19 at 6:10
  • 1
    $\begingroup$ Simply try FourierSeries[expr,n] which gives you the complex form of the FourierSeries $\endgroup$ Feb 19 at 9:09
  • $\begingroup$ Hmm thanks for that. It seems to do the job, albeit very slowly. I presume under the hood it is performing integration ... whereas the replacements I was doing were almost instantaneous (albeit sometimes doing the wrong thing). It would be nice if FourierSeries (and FourierTrigSeries) had an option to reorganize terms (that are already almost in the right form), rather than doing a long brute force computation. $\endgroup$
    – ions me
    Feb 19 at 21:07
  • $\begingroup$ Also, I'm still curious how one would do this with Collect. It seems like something that should be easy, but it never works quite right. $\endgroup$
    – ions me
    Feb 19 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.