Is is possible to use NDSolve
with DiscreteVariables
if there are no continuous-time variables?
This fails:
NDSolve[{x[0] == 1,
WhenEvent[Mod[t, 1] == 0, x[t] -> -x[t]]}, {x}, {t, 0, 7},
DiscreteVariables -> {x}]
It works if I remove the DiscreteVariables
, replacing it with $x'(t)=0$:
NDSolveValue[{x[0] == 1, x'[t] == 0,
WhenEvent[Mod[t, 1] == 0, x[t] -> -x[t]]}, {x}, {t, 0, 7}]
(This seems to defeat the purpose of DiscreteVariables
.)
It works if I introduce a "dummy" continuous-time variable:
NDSolveValue[{y'[t] == 0, y[0] == 0, x[0] == 1,
WhenEvent[Mod[t, 1] == 0, x[t] -> -x[t]]}, {x, y}, {t, 0, 7},
DiscreteVariables -> {x}]
(This seems like a hack.)
I ask because I have a system of equations
$$x_i(T_i^{k+1})=\sum_{j=1}^N a_{i,j} x_j(T_i^k), \quad i=1,\ldots,N$$
where each variable $x_i(t)$ changes only at the discrete times $\{T_i^k\}_{k \in \mathbb{N}}$.
Thoughts?
NDSolve
is the only built-in way to construct a discontinuousInterpolatingFunction
(see here for a manual method). If if one knows ahead of time the times that the variable changes, one could directly construct aPiecewise
function (see here or here).... $\endgroup$ – Michael E2 May 18 '16 at 12:07FunctionInterpolation
takes a global approach likeNIntegrate
.NDSolve
takes a local approach, but primarily for order > 0; however, via DAEs, it can simultaneously do order-0 integrations. I don't think there's an analog ofFunctionInterpolation
. $\endgroup$ – Michael E2 May 18 '16 at 12:07