2

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.)

Escall
  • 31
  • 4
  • This sort of error is discussed in https://mathematica.stackexchange.com/q/43513/1063. I would call it a bug. – bbgodfrey Jan 20 '24 at 13:08
  • Also, @Michael_E2 might have some advice. – bbgodfrey Jan 20 '24 at 13:37
  • @bbgodfrey, thanks! I found the comment that NumericalFunction penetrates the barrier of _?NumericQ but no explicit discussion about Experimental`NumericalFunction::nlnum1 through the link you sent. Do you think that's the problem here? – Escall Jan 24 '24 at 09:20

0 Answers0