In[]:=
Clear["Global`*"];
In[]:=
utest=ListInterpolation[Table[,{i,0,3}],{0,3},InterpolationOrder1];utest1[t_?NumericQ/;0<=t<=3]:=utest[t];utest1[_?NumericQ]=0;Plot[utest1[t],{t,0,5}]
2
i
Out[]=
In[]:=
ysol1=NDSolveValue[{y'[t]==utest1[t],y[0]==0},y,{t,0,5}]
Out[]=
InterpolatingFunction
This method was taken from the following web posting:
https://mathematica.stackexchange.com/questions/164257/interpolatingfunctiondmval-error-in-the-piecewise-function-with-an-interpolati
In contrast, the “obvious” way of proceeding, using Piecewise[...] gives an extrapolation bug, because the discontinuity in the function erroneously generates an “Event” in the code:
https://mathematica.stackexchange.com/questions/164257/interpolatingfunctiondmval-error-in-the-piecewise-function-with-an-interpolati
In contrast, the “obvious” way of proceeding, using Piecewise[...] gives an extrapolation bug, because the discontinuity in the function erroneously generates an “Event” in the code:
In[]:=
utest=ListInterpolation[Table[,{i,0,3}],{0,3},InterpolationOrder1];utest2[t_]:=Piecewise[{{utest[t],0<=t<=3}},0]Plot[utest2[t],{t,0,5}]
2
i
Out[]=
In[]:=
ysol2=NDSolveValue[{y'[t]==utest2[t],y[0]==0},y,{t,0,5}]
Out[]=
InterpolatingFunction
The two methods give nearly the same result, with a slight difference occurring at the discontinuity.
In[]:=
Plot[ysol1[t]-ysol2[t],{t,0,5}]
Out[]=