So I have a function myfun
with positive domain that I got from NDSolve and a bunch of transformations afterwards. I can plot it on its own like
Plot[myfun[t], {t, 0, 6}]
but when I try to insert it into a Piecewise function like
Plot[Piecewise[{{myfun[t], t > 0 && t < 6}}], {t, -6, 6}]
or
Plot[Piecewise[{{myfun[t], t > 0 && t < 6}, {1, t<=0}}], {t, -6, 6}]
it gives me warnings
InterpolatingFunction::dmval: Input value {-5.99975} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
and doesn't plot the function myfun
.
What is even more weird, I was unable to create a minimal working example, because something like
Plot[Piecewise[{{Interpolation[{1, 2, 3, 5, 8, 5}][t],
t > 0 && t < 6}}], {t, -6, 6}]
works just fine!
What could be the problem here?
EDIT:
Plot[Piecewise[{{Sqrt[Interpolation[{1, 2, 3, 5, 8, 5}][t]], t > 1 && t < 6}}], {t, -6, 6}]
generates the same warnings, but does draw the plot. (Note that domain and range of the function under square root are positive.)
EDIT 2: Here's reduced code that has the problem
soln = NDSolve[{y'[t] == 1/(1/(1 + Cos[y[t]]))^2, y[0] == 0}, y, {t, 0, 10}]
pw = Piecewise[{{1, t < 0}, {y[t] /. soln, t > 0}}]
Now
Plot[pw /. x -> t, {t, 0, 10}, PlotRange -> All]
works but
Plot[pw /. x -> t, {t, -1, 10}, PlotRange -> All]
doesn't.
NDSolve[]
-generatedInterpolatingFunction[]
that generates that error? $\endgroup$