5
$\begingroup$

While trying to compute Fourier Series, i find that It doesn't evaluate both positive and negative parts and hence apparently giving wrong answer. Below is the code that i tried:

 Clear[t, a, b, c, fn];
 fn[t_] := (a*Cos[t])/(b + c*(Cos[t])^2)^2;
 FourierSeries[fn[t], t, 3]

and it gives following output:

 (8 a E^(3 I t))/c^2

This can't be correct since i started with a real function. I then tried computing the co-efficient directly as below:

 1/(2 \[Pi]) Integrate[fn[t]*E^(3 I t), {t, -\[Pi], \[Pi]}]
 1/(2 \[Pi]) Integrate[fn[t]*E^(-3 I t), {t, -\[Pi], \[Pi]}]

that gives:

(4 a)/c^2
(4 a)/c^2

What is the reason for this difference? Could someone point me out as to how i can make Mathematica do the same for me?

$\endgroup$
8
  • $\begingroup$ Did you check the FourierParameters setting? $\endgroup$ Commented Oct 13, 2017 at 10:45
  • $\begingroup$ No, i wasn't aware of it! $\endgroup$ Commented Oct 13, 2017 at 10:48
  • $\begingroup$ Right, so check that the setting is compatible with whatever definition of the Fourier series you're using, and set accordingly. (This applies for all Fourier-related Mathematica functions.) $\endgroup$ Commented Oct 13, 2017 at 10:49
  • $\begingroup$ I can't see how i am going to use it in the code i've written above. I found something similar for Fourier transform, but not for the series. $\endgroup$ Commented Oct 13, 2017 at 10:59
  • 2
    $\begingroup$ There is something off here.. FourierCoefficient would seem to be what you want, however it Yields 8 a/c^2 . Also if I specify values for the constants the direct integration and the FourierCoefficient give completely different results. Maybe someone who gets this should write up an answer. $\endgroup$
    – george2079
    Commented Oct 13, 2017 at 15:27

1 Answer 1

3
$\begingroup$

I think FourierSeries and FourierCoefficient are bugged here. To get the result you want, you could use FourierCosSeries or FourierCosCoefficient, or, if you're careful, Integrate.

We can simplify a little by pulling a/b^2 out and defining c -> b d, to give

f = Cos[t]/(1 + d Cos[t]^2)^2;  

Then we have

series = FourierCosSeries[f, t, 3, Assumptions -> d > 0]

(* Cos[t]/(1 + d)^(3/2) + 
  ((8 (-1 + Sqrt[1 + d]) + d (-12 - 3 d + 8 Sqrt[1 + d])) Cos[3 t])/(d^2 (1 + d)^(3/2)) *)

The result looks pretty good for d = 1:

Plot[Evaluate[{f, series} /. d -> 1], {t, -Pi, Pi}]

Mathematica graphics

You can also get the correct results for the Fourier coefficients using Integrate if you assume that d > 0:

Table[Integrate[f Exp[-k I t], {t, -Pi, Pi}, Assumptions -> d > 0]/(2 Pi), {k, -3, 3, 2}]

(* 
{
  (8 (-1 + Sqrt[1 + d]) + d (-12 - 3 d + 8 Sqrt[1 + d]))/(2 d^2 (1 + d)^(3/2)), 
  1/(2 (1 + d)^(3/2)), 
  1/(2 (1 + d)^(3/2)), 
  (8 (-1 + Sqrt[1 + d]) + d (-12 - 3 d + 8 Sqrt[1 + d]))/(2 d^2 (1 + d)^(3/2))
} 
*)

With no assumptions, however, you won't get useful results:

Table[Integrate[f Exp[-k I t], {t, -Pi, Pi}]/(2 Pi), {k, -3, 3, 2}]

(* {0, 0, 0, 0} *)

Now, what is going on with FourierSeries?

FourierSeries[f, t, 3]

(* (8 E^(3 I t))/d^2 *)

Not really sure, but note that it is giving the same result as for the function expanded around d -> Infinity:

Normal@Series[f, {d, Infinity, 0}]

(* Sec[t]^3/d^2 *)

FourierSeries[Sec[t]^3/d^2, t, 3]

(* (8 E^(3 I t))/d^2 *)

This is clearly wrong. It isn't even the correct series for Sec[t]^3, and adding assumptions on d doesn't help here. FourierCoefficient gives the same thing:

Table[FourierCoefficient[Sec[t]^3/d^2, t, k], {k, -3, 3, 2}]

(* {0, 0, 0, 8/d^2} *)

If we pull out the d^2, we get a slightly more reasonable result:

Table[FourierCoefficient[Sec[t]^3, t, k], {k, -3, 3, 2}]/d^2

(* {4/d^2, 0, 0, 4/d^2} *)

So it seems like there are definitely some problems going on here.

$\endgroup$
2
  • $\begingroup$ Nice! Consider sending a bug report, perhaps? $\endgroup$ Commented Oct 14, 2017 at 6:31
  • $\begingroup$ incredible that this bug is still around in Mathematica 14.0 $\endgroup$ Commented Aug 26 at 16:05

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.