Hi!
I'm having a really bizarre issue with WhenEvent--when I define a variable as some equation involving the variables that are defined and used in NDSolve, I get the following error: NDSolve::nbnum1: The function value Abs[x[t]-y[t]]>0.01 is not True or False when the arguments are {0.,0.3,0.2,0.3,0.2}.
However, when I input the equation as it is (not previously defined as a variable), the solver runs fine. Here's a simplified version of my code.
variable = Sqrt[Abs[x[t] - y[t]]^2]
times = {};
Print["Current time step in ODE solution ="];
Monitor[
s = NDSolve[{x'[t] == x[t], y'[t] == y[t], y[0] == 0.2, x[0] == 0.3,
WhenEvent[variable > 0.01, Print[2]]}, {x[t], y[t]}, {t, 0,
tAnneal}, Method -> {"EquationSimplification" -> "Residual"},
EvaluationMonitor :> AppendTo[times, t]], times[[-1]] ];
This version throws an error. However, when I input
times = {};
Print["Current time step in ODE solution ="];
Monitor[
s = NDSolve[{x'[t] == x[t], y'[t] == y[t], y[0] == 0.2, x[0] == 0.3,
WhenEvent[Sqrt[Abs[x[t] - y[t]]^2] > 0.01, Print[2]]}, {x[t],
y[t]}, {t, 0, tAnneal},
Method -> {"EquationSimplification" -> "Residual"},
EvaluationMonitor :> AppendTo[times, t]], times[[-1]] ];
it works fine. This is an issue for me because I have a big datastructure with such equations for many different variables, and I need to be able to call an element of that list rather than writing in the equation itself.
Thank you for any help you all can give me!
Kaden