2
$\begingroup$

I'm solving an ODE system with multiple events and find the discrete variable not updated as expected because one of the events is not triggered. During narrowing down the problem, I find something strange and cannot explain. Here are the simplified cases.

Case 1 works perfectly in the sense that the two events occur as expected. Case 2 does not work. Case 3 works by removing the action a[t] -> t in case 2 although the discrete variable won't get updated any longer.

Case 1

NDSolveValue[{y'[t] == Cos[t], y[0] == a[0] == 0, 
  WhenEvent[y[t], {Print[1], a[t] -> t}], 
  WhenEvent[t == a[t] + 0.1, Print[3]]}, y, {t, 0, 20}, DiscreteVariables -> a]

Case 2

NDSolveValue[{y'[t] == Cos[t], y[0] == a[0] == 0, 
  WhenEvent[y'[t], {Print[1], a[t] -> t}], 
  WhenEvent[t == a[t] + 0.1, Print[3]]}, y, {t, 0, 20}, DiscreteVariables -> a]

Case 3

NDSolveValue[{y'[t] == Cos[t], y[0] == a[0] == 0, 
  WhenEvent[y'[t], Print[1]], 
  WhenEvent[t == a[t] + 0.1, Print[3]]}, y, {t, 0, 20}, DiscreteVariables -> a]

Maybe this issue is not relevant to the real case. But how to understand the action a[t] -> t will stop the event from happening while it is not even part of the ODE? And why is only y' affected in this case?

$\endgroup$
2
  • 1
    $\begingroup$ In case 2, I get that the integration stops at the starting value t == 0. The events never happen. So, to me, the first question to investigate is why NDSolve[] quits right away. $\endgroup$ Commented Oct 21 at 18:04
  • 3
    $\begingroup$ A tentative answer is that Null, the value returned by Print[1], is not really a valid action. Sometimes it causes trouble, sometimes it doesn't (~ GIGO). If the action is {Print[1]; a[t] -> t}, then it seems to work. $\endgroup$ Commented Oct 21 at 18:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.