16

Bug introduced in 11.1.0 and persisting through 11.1.1


In V11.1,

NSolve[BesselJ[0, x] == 0 && 0 < x < 20, x]

returns no solutions:

Mathematica graphics

But in V11.0 (and earlier), it returns all solutions:

Mathematica graphics

Is there anyway to get NSolve to solve this equation in V11.1?

(Interestingly, Solve[BesselJ[0, x] == 0 && 0 < x < 20, x] works in both, but I was particularly interested NSolve, since I was wanting to compare it with other numerical methods.)

user58955
  • 617
  • 3
  • 9
Michael E2
  • 235,386
  • 17
  • 334
  • 747

2 Answers2

14

Is there anyway to get NSolve to solve this equation in V11.1?

Adding Complexes makes it work

    NSolve[BesselJ[0, x] == 0 && 0 < x < 20, x, Complexes]

Mathematica graphics

Nasser
  • 143,286
  • 11
  • 154
  • 359
  • it works in 11.1 – Rom38 Apr 18 '17 at 04:35
  • Thanks! NSolve[BesselJ[0, x] == 0 && 0 < Re[x] < 20, x] and NSolve[BesselJ[0, x] == 0 && 0 < Re[x] < 20 && Im[x] == 0, x] also work (suggested by your answer). I don't understand the reason for the change, since it breaks previous code. – Michael E2 Apr 18 '17 at 11:58
  • Works for other special functions, too. But NSolve[Zeta[x] - 2 == 0 && 0 < Re@x < 2 && Im[x] == 0, x] takes 4.5 sec and NSolve[Zeta[x] - 2 == 0 && 1 < x < 2, x, Complexes] takes 18.5 sec.; NSolve[-2 + Zeta[x] == 0 && 1 < Re[x] < 2, x] fails (but that's not surprising -- I was more surprised it worked on the Bessel funciton). – Michael E2 Apr 18 '17 at 13:28
13

It is a bug in V11.1. As a workaround, you can put the following in your init.m file.

Reduce`RealTNRoots;
nonElementaryQ[f_] := Module[{x}, !ListQ[Simplify`FunctionSingularities[f[x], x, "ELEM"]]]
System`TRootsDump`NIntervalRoots[f_?nonElementaryQ, ii_, prec_] := $Failed

This will disable the offending code for non-elementary functions.

In[4]:= NSolve[BesselJ[0, x] == 0 && 0 < x < 20, x]
Out[4]= {{x -> 2.40483}, {x -> 5.52008}, {x -> 8.65373}, {x -> 11.7915},
>    {x -> 14.9309}, {x -> 18.0711}}
Adam Strzebonski
  • 3,510
  • 23
  • 17