I'm trying to solve an ODE numerically with NDSolve but get an unexpected error message (Experimental`NumericalFunction::nlnum1), and the domain of the returned solution is empty. I get this error whenever I simultaneously have an event with "IntegrateEvent" -> True, a discrete variable and am using arbitrary-precision arithmetic (e.g. WorkingPrecision -> 30).
Minimal example (version: 13.3.1 for Microsoft Windows (64-bit)):
NDSolve[{x'[t] == 1, x[0] == 0, y[0] == 1, WhenEvent[Abs[x[t]] > 1, , "IntegrateEvent" -> True]},
{x, y}, {t, 0, 2}, DiscreteVariables -> {y \[Element] {-1, 1}}, WorkingPrecision -> 30]
(* Experimental`NumericalFunction: The function value <<1>> is not a list of numbers with dimensions {2}
when the arguments are {0,{0,-1.`30.},{1.`30.}}.*)
If the event is not integrated, y not discrete or the working precision MachinePrecision, the error goes away, i.e. all of the following return the expected solution (although I'm not sure why the last one does not give NDSolve::underdet).
NDSolve[{x'[t] == 1, x[0] == 0, y[0] == 1, WhenEvent[Abs[x[t]] > 1, , "IntegrateEvent" -> False]},
{x, y}, {t, 0, 2}, DiscreteVariables -> {y \[Element] {-1, 1}}, WorkingPrecision -> 30]
NDSolve[{x'[t] == 1, x[0] == 0, y[0] == 1, WhenEvent[Abs[x[t]] > 1, , "IntegrateEvent" -> True]},
{x, y}, {t, 0, 2}, DiscreteVariables -> {y \[Element] {-1, 1}}, WorkingPrecision -> MachinePrecision]
NDSolve[{x'[t] == 1, x[0] == 0, y[0] == 1, WhenEvent[Abs[x[t]] > 1, , "IntegrateEvent" -> True]},
{x, y}, {t, 0, 2}, WorkingPrecision -> 30]
Is this a bug or can anyone understand what's going on?
Update:
The problem seems to be the Abs. The following also works as expected
NDSolve[{x'[t] == 1, x[0] == 0, y[0] == 1, WhenEvent[x[t] > 1, , "IntegrateEvent" -> True]},
{x, y}, {t, 0, 2}, DiscreteVariables -> {y \[Element] {-1, 1}}, WorkingPrecision -> 30]
(The Abs is easy to remove in this minimal example but not in the actual problem.)
NumericalFunctionpenetrates the barrier of_?NumericQbut no explicit discussion aboutExperimental`NumericalFunction::nlnum1through the link you sent. Do you think that's the problem here? – Escall Jan 24 '24 at 09:20