I have noticed strange behavior of WhenEvent in the case where the body of WhenEvent is satisfied in the first step. For example,
NDSolve[{y'[x] == y[x], y[0] == 1,
WhenEvent[
y[x] > 1, {"StopIntegration"}]}, y, {x, 0,
10}]
integrates equation until x=10 (and not x=0). However, if I put
NDSolve[{y'[x] == y[x], y[0] == 1,
WhenEvent[
y[x] > 1 || (x > 2 && y[x] > 1), {"StopIntegration"}]}, y, {x, 0,
10}]
domain of integration will be 1.43*10^-14., while I would expect that domain is either 0 or 1. This is just an example of the more complicated ParametricNDSolve that I am working with. I would like to understand why is this happening and how could I require that if the body is satisfied in the first step, domain of integration becomes 0 or 1 or some other arbitrary number that I want.
FalsetoTrue. If the condition starts in theTruestate, then it is not an event for it to remain true. (2) The conditionsy[x] > 1,y[x] == 1, andy[x] < 1are each a special form ofy[x] == 1. They each detecty[x]*crossing* the value1in one of three ways: increasing, either increasing or decreasing, or decreasing, respectively. This is in the docs under "Details and Options." Starting at the value1,y[x]cannot *cross* it. – Michael E2 Nov 01 '20 at 20:40y[x]was below1before the step andy[x]was above1after the step. Similarly for "decreasing." When the step (change in x) is negative, this definition of "increasing" means the slope (y'[x]) is negative. Likewise for "decreasing." – Michael E2 Nov 01 '20 at 20:49psol = ParametricNDSolveValue[sys, vars, params,...]; trial[paramvals_] := If[<test paramvals for WhenEvent condition>, $Failed, psol[paramvals]]and test parameter settings by callingtrial[]on them, which would callpsolonly when appropriate. – Michael E2 Nov 01 '20 at 20:53