0
$\begingroup$

Hi I need help to fix my issue , I need to plot the following code for n values f[y_] := Piecewise[{{1, (2 n + 1) <= y <= (2 n + 2)}, {0, True}}] n=-1,-2,-3,4,5,5

$\endgroup$
0
2
$\begingroup$

Something like this?

f[n_][y_] := Piecewise[{{1, (2 n + 1) <= y <= (2 n + 2)}, {0, True}}]

Plot[Evaluate[f[#][y] & /@ {-1, -2, -3, 4, 5}], {y, -3, 3}, PlotLegends -> "Expressions", PlotRange -> All, Frame -> True]

enter image description here

$\endgroup$
6
  • $\begingroup$ thank you , but not work what you did $\endgroup$ – user55346 Feb 17 '18 at 5:33
  • $\begingroup$ @user55346 What you mean? $\endgroup$ – zhk Feb 17 '18 at 5:43
  • $\begingroup$ i meant your code does not work when I run it $\endgroup$ – user55346 Feb 17 '18 at 6:04
  • $\begingroup$ @user55346 Quit kernel then run it again $\endgroup$ – zhk Feb 17 '18 at 6:05
  • $\begingroup$ Note that f = Function[n, Function[y, Piecewise[{{1, (2 n + 1) <= y <= (2 n + 2)}, {0, True}}]] ]; can also come in handy in many cases. $\endgroup$ – Henrik Schumacher Feb 17 '18 at 9:54

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