While trying out @MichaelSeifert's answer to Eliminating Discontinuities When Using Mod with NDSolve and Plot for Oscillators, I came across this odd behavior. Depending on how an Mod[InterpolatingFunction[t], 1] is evaluated, the discontinuities of Mod[] are connected or not.

soln = x -> Interpolation[{#, #}\[Transpose] &@Range[0, 4]];
Plot[Mod[x[t] /. soln, 1], {t, 0, 4}]           (* connected *)
Plot[Mod[soln[[2]][t], 1], {t, 0, 4}]           (* disconnected *)
Plot[Evaluate@Mod[soln[[2]][t], 1], {t, 0, 4}]  (* connected *)

The connections persist in the following cases:

  • The option Exclusions -> "Discontinuities" is given.
  • fn = Mod[soln[[2]][t], 1] is set and Plot[fn,..] is plotted.
  • fn = x[t] /. soln is set and Plot[Mod[fn, 1],..] is plotted.

The discontinuities are disconnected in the following cases:

  • fn = soln[[2]] is set and Plot[Mod[fn[t], 1],..] is plotted.
  • fn = x /. soln is set and Plot[Mod[fn[t], 1],..] is plotted.

I've tried other cases, mainly adding or removing Evaluate, but they don't seem worth mentioning.

What is going on? Is there a way to get the discontinuities disconnected in all cases? Does it look like a bug?


This site is temporarily in read only mode and not accepting new answers.

Browse other questions tagged .