# Plotting a periodic function [duplicate]

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?

• One usually uses Mod[] for the purpose; see e.g. this and this. Apr 10 '16 at 13:17

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]
}]


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