# A newbie question about the use of the FourierSeries functions

Although I have had no previous experience with the Mathematica Fourier Series functions ( or package ), I am writing a tutorial on Fourier Analysis and Transformations in a Mathematica Notebook, using a standard ( not high-end ) Windows PC which runs Mathematica 11.3 usually with excellent performance ( how relative and unspecific that may sound ).

I started with an example using the following code.

 ClearAll[f, g, h];
f[x_] := Piecewise[{{3, 0 < x < 1}, {-3, 1 < x < 2}}]
g[x_] := f[Mod[x, 2]]
h[x_] = FourierSeries[g[x], x, 30];
Show[
Plot[g[x], {x, -1, 3}, Filling -> Axis],
Plot[h[x], {x, -1, 3}],
PlotRange -> {-4, 4}
]


This code ran as expected, with the following output. Then, I changed the code to:

 ClearAll[f, g, h, k];
f[x_] := Piecewise[{{3, 0 < x < 1}, {-3, 1 < x < 2}}]
g[x_] := f[Mod[x, 2]]
h[x_] = FourierSeries[g[x], x, 30];
k[x_] = FourierTrigSeries[g[x], x, 30];
Show[
Plot[g[x], {x, -1, 3}, Filling -> Axis],
Plot[h[x], {x, -1, 3}],
Plot[k[x], {x, -1, 3}],
PlotRange -> {-4, 4}
]


( Note the addition of k(x) with the purpose to compare FourierSeries and FourierTrigSeries ).

Performance degraded considerably... I checked the Windows 10 Performance Monitor : memory consumption was as high as I have ever seen. My point is that running this code took ( probably >> 10 times ) the time it took to run the first batch of code.

The output... was exactly the same ( which was to be expected ). If you forgive my lack of experience with the FourierSeries type of functions I have the following questions:

• Is the specification of my code such that the execution is not optimal?
• Why is there such a difference in run-time between FourierSeries and FourierTrigSeries?
• Do you have any other tips, advice or links for newbie users of the FourierSeries functions?
• Minor commnet, your f is 3 SquareWave[x/2]. – b.gates.you.know.what Apr 26 '19 at 13:53
• New to me, thanks. – nilo de roock Apr 26 '19 at 14:13
• The only possible explanation I can see for this is a flaw in Mathematica's implementation of FourierTrigSeries – mikado Apr 26 '19 at 15:27
• I absolutely second what mikado said. Best to tell Wolfram Support about the issue. – Henrik Schumacher Apr 26 '19 at 16:00
• Using SquareWave things speeded up though. I'll test it in Mma 12 which I'll install today. – nilo de roock May 1 '19 at 11:57