1
$\begingroup$

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.

enter image description here

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.

enter image description here

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 ).

enter image description here

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?
$\endgroup$
  • 2
    $\begingroup$ Minor commnet, your f is 3 SquareWave[x/2]. $\endgroup$ – b.gates.you.know.what Apr 26 at 13:53
  • $\begingroup$ New to me, thanks. $\endgroup$ – nilo de roock Apr 26 at 14:13
  • 1
    $\begingroup$ The only possible explanation I can see for this is a flaw in Mathematica's implementation of FourierTrigSeries $\endgroup$ – mikado Apr 26 at 15:27
  • 1
    $\begingroup$ I absolutely second what mikado said. Best to tell Wolfram Support about the issue. $\endgroup$ – Henrik Schumacher Apr 26 at 16:00
  • $\begingroup$ Using SquareWave things speeded up though. I'll test it in Mma 12 which I'll install today. $\endgroup$ – nilo de roock May 1 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.