# Some Problem with WhenEvent!

Anyone knows what's the problem with the following code and how can I fix it? I am not sure that I wrote the WhenEvent section correctly. By the way, I want to solve the equations and then plot y vs. y' when x goes to zero (it is obvious that it's an interval :) ).

Thanks

tmax = 300;
{{sol1}, {ps}} = Reap[
NDSolve[
{x'[t] == -(x[t] + 2 x[t] y[t]),
y'[t] == -x[t] x[t] + y[t] (y[t] - 1),
x[0] == 0.1, y[0] == 0.1,
WhenEvent[Limit[x[t], x[t] -> 0], Sow[t]]},
{x, y},
{t, 0, tmax}]]

-

The condition in WhenEvent should be Boolean (True/False). The function Limit yields a number when the limit exists. In your case, the limit is 0, provided x is an undefined symbol.*

Perhaps you want something like this:

tmax = 300;
{{sol1}, {ps}} =
Reap[NDSolve[{x'[t] == -(x[t] + 2 x[t] y[t]),
y'[t] == -x[t] x[t] + y[t] (y[t] - 1), x[0] == 0.1, y[0] == 0.1,
WhenEvent[x[t] == 0, Sow[t]]}, {x, y}, {t, 0, tmax}]]

(* Out:
{{{x -> InterpolatingFunction[{{0., 300.}}, "<>"],
y -> InterpolatingFunction[{{0., 300.}}, "<>"]}},
{{20.5968}}} *)


*In general Limit[f[t], f[t] -> 0] won't evaluate if f is defined, say, f[t_] := 1+t. (Mathematically Limit represents the limit of the first expression, treating the second as an independent variable.)

-