0
$\begingroup$

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}]
$\endgroup$
1
  • 1
    $\begingroup$ Please clarify which function you want to plot. $\endgroup$
    – A.G.
    Commented Aug 7, 2019 at 11:50

1 Answer 1

4
$\begingroup$

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

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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