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
    $\begingroup$ Please clarify which function you want to plot. $\endgroup$ – A.G. Aug 7 at 11:50
3
$\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$
  • $\begingroup$ Thanks, this work well, Please let me know the function of X := Mod[x, 4]; in this code $\endgroup$ – MKA Sep 7 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. Sep 7 at 16:11

Your Answer

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

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