2
$\begingroup$

My question is the following: how can I plot a function repeatedly? By following some topics here I found some basic information about using Fourier series. This is what I made:

f = Piecewise[{{x + π, -π < x < 0}, {x - π, 0 < x < π}}];
g = FourierSeries[f, x, 2];
Plot[{g, f}, {x, -10, 10}]

This plots the Fourier series over all periods, but only plots my original function for one period. I need to repeat it periodically as follows: $f(x)(k\,E\,Z)=f(x+2\,k\,\pi)$

What do I have to do to get that?

$\endgroup$
1
  • 1
    $\begingroup$ One usually uses Mod[] for the purpose; see e.g. this and this. $\endgroup$
    – J. M.'s torpor
    Apr 10 '16 at 13:17
2
$\begingroup$

You are right István Sikari-Nágl, it is not as easy at all as it looks.

f[x_] = Piecewise[{{x + π, -π < x < 0}, {x - π, 0 < x < π}}];
g = FourierSeries[f[x], x, 2] // ExpToTrig
(* -2 Sin[x] - Sin[2 x] *)

Edit

Now I build the periodic function.

Column[{
  Plot[f[Mod[x,-2 Pi]], {x,-3 Pi, 3 Pi}, Exclusions -> None, ImageSize -> 250],

  Plot[f[Mod[x, 2 Pi]], {x,-3 Pi, 3 Pi}, Exclusions -> None, ImageSize -> 250],

  Plot[f[Mod[x,-2 Pi]] + f[Mod[x, 2 Pi]], {x,-3 Pi, 3 Pi},Exclusions -> None, ImageSize -> 250],

  Plot[{g, f[Mod[x, 2 Pi,-Pi]]}, {x,-3 Pi, 3 Pi}, Exclusions -> None, ImageSize -> 250]
  }]

enter image description here

$\endgroup$
2
  • $\begingroup$ More compactly: f[Mod[x, 2 π, -π]] $\endgroup$
    – J. M.'s torpor
    Apr 10 '16 at 14:54
  • $\begingroup$ Thanks @ J. M. I wanted to show from which parts the periodical function exists $\endgroup$
    – user36273
    Apr 10 '16 at 18:32

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