# Extending periodic piecewise continuous function

I need to plot the piecewise function

$$f(x) = \left\{ \begin{array}{r} x^2, & -2 \leq x \leq 0, \\ 0, & 0 < x \leq 1, \\ 1 - x, & 1 < x \leq 3. \\ \end{array} \right.$$

as a periodic function on an extended interval. The duplication of the like problem I see here seems to be working only for that specific case

f1[y_] := f[Mod[y, 4]]
Plot[f1[x], {x, -8, 8}]

• Please clarify which function you want to plot. – A.G. Aug 7 at 11:50

I do not understand exactly what your function is; you may want to try something along these lines:

X := Mod[x, 4];
f[x_] := Piecewise[{
{0, X <= 1},
{1 - X, 1 <= X <= 3},
{X^2, X <= 4}
}]
Plot[f[x], {x, -3, 10}]


• Thanks, this work well, Please let me know the function of X := Mod[x, 4]; in this code – MKA Sep 7 at 1:35
• It is just a replacement to avoid typing Mod[x, 4] several times. You can read the documentation of SetDelayed. – A.G. Sep 7 at 16:11