I would like to use StopIntegration
in WhenEvent
, when more than one condition should be checked. For example, in the code below I would like to integrate until either q1[t] == 0
or q2[t] == 0
sol[s_] :=
NDSolve[{q1'[t] == -q2[t], q2'[t] == q1[t], q1[0] == Cos[s],
q2[0] == Sin[s],
WhenEvent[
q1[t] == 0 || q2[t] == 0, {tmax = t, "StopIntegration"}]}, {q1,
q2}, {t, 0, 10}]
But it does not work, when I try to check it
Manipulate[
ParametricPlot[
Evaluate[{q1[t], q2[t]} /. sol[s], {t, 0, tmax},
PlotRange -> 1], {{s, Pi/4}, 0, 2 Pi}]
although it works perfectly if I leave only one of the conditions. Of course in this simple example I can just write q1[t]q2[t]==0
, but I would like to understand how to proceed in general with more complex conditions.
Thank you in advance.
WhenEvent[{q1[t] == 0, q2[t] == 0}, {youractions}]
. Take a look at the "Scope" section of the WhenEvent docs, under "Events", for a similar example. $\endgroup$q2[t] == 0 && q1[t] > 0
works, butq1[t] > 0 && q2[t] == 0
does not. $\endgroup$WhenEvent
expression work at a time. It would stand to reason that it should accept compound conditions, but either it just doesn't, or I have not found a way to coax it to do it yet... $\endgroup$f == 0
andf == 0 && pred
, also with<
,>
, andMod
, are special cases inWhenEvent
(see mathematica.stackexchange.com/questions/39374/…), compared to the generalpred
, where the "event" ispred
changing fromFalse
toTrue
. $\endgroup$