1

I've noticed that when "Mod" and "Which" are used to the same effect, they plot to slightly different results. Take the following example:

f[x_] = 2 x;
fmod[x_] = Mod[f[x], 1];
Plot[fmod[x], {x, 0, 1}]
fwhich[x_] = Which[x < 1/2, f[x], x > 1/2, f[x] - 1];
Plot[fwhich[x], {x, 0, 1}]

The output graphs are:

enter image description here

enter image description here

How can I graph Which without getting that connecting line?

Max
  • 1,050
  • 6
  • 14

1 Answers1

5

As MarcoB already pointed out in the comments, Piecewise is probably the better alternative.

Additionally, we already have a related question with good answers where you can steal ideas from:

f[x_] = 2 x;
fmod[x_] = Mod[f[x], 1];
fwhich[x_] = Which[x < 1/2, f[x], x > 1/2, f[x] - 1];
Plot[fwhich[x], {x, 0, 1}, Exclusions -> {1/2}]

Mathematica graphics

halirutan
  • 112,764
  • 7
  • 263
  • 474