Bug introduced in 7.0 and persisting through 13.2
I was trying to plot a phase portrait (StreamPlot
) using a piecewise (Piecewise
) defined function as
f[x_] := Piecewise[{{2 x - 3, x > 1}, {-x, -1 <= x <= 1}, {2 x + 3, x < -1}}]
StreamPlot[{y - f[x], -x}, {x, -5, 5}, {y, -5, 5}]
It does not produce a plot and gives: Part::partw: Part 1 of {} does not exist
.
I am using Version: 11.0.1.0, Windows, 64-bit.
I found this previous post, How I can make the StreamPlot of this differential equation?. The following worked in some previous version of Mathematica (but same problem as I see above with copy-and-paste).
StreamPlot[{1, Piecewise[{{0.4 p (1 - p/30), 0 < t <= 5},
{0.4 p (1 - p/30) - 0.25 p, t >= 5}}]}, {t, 0, 10}, {p, -5, 5}]
Did something break and there is a bug? Any way around it (maybe I should try defining it using unit step functions and seeing if that resolves the matter)?