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?
NDSolveis 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 aPiecewisefunction (see here or here).... – Michael E2 May 18 '16 at 12:07FunctionInterpolationtakes a global approach likeNIntegrate.NDSolvetakes 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. – Michael E2 May 18 '16 at 12:07WhenEventalso doesn't support time delays as discussed here. This madeNDSolveseem ill-suited for my problem. I filed a bug/feature report with Wolfram and solved the system of equations "by hand". – ConvexMartian May 20 '16 at 13:18RecurrenceTablelike this:RecurrenceTable[{x[t + 2] == -x[t], x[0] == 1, x[1] == 1}, x, {t, 0, 10}]. This addresses theNDSolveexample above but not for the weird hybrid system of equations I wrote out in math. – ConvexMartian Jun 03 '16 at 18:28