Can a time-based WhenEvent be triggered at the initial time within NDSolve? As a minimal example, a pulse is to be applied every integer time t, but NDSolve skips the initial pulse at t=0:
sol = NDSolve[{x'[t] == -x[t], x[0] == 0, WhenEvent[Mod[t, 1], x[t] -> x[t] + 1]},
x, {t, 0, 1}][[1]];
Plot[x[t] /. sol, {t, 0, 1}]
One possible solution is to give the initial values just before t=0:
sol = NDSolve[{x'[t] == -x[t], x[-$MachineEpsilon] == 0,
WhenEvent[Mod[t, 1], x[t] -> x[t] + 1]}, x, {t, 0, 1}][[1]];
Plot[x[t] /. sol, {t, 0, 1}]
but this leaves me slightly uneasy, because in general, the system will vary in the small time between t=-$MachineEpsilon and t=0. Also x[0]/.sol yields 0. instead of 1. even with this hack.
Is there a better way for such a time-based WhenEvent to be triggered at the initial time?





WhenEvent:WhenEvent[ t == $MachineEpsilon , .. ]Obviously for this example you could just set initial conditionx[0]=1, you might want to come up with a not-so-trivial example. – george2079 Aug 09 '16 at 21:45