16
$\begingroup$

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

$\endgroup$
  • $\begingroup$ It's weird that this only happens for special functions; with elementary functions like the trigonometric functions, NSolve[] works fine. $\endgroup$ – J. M. will be back soon Apr 18 '17 at 13:54
  • $\begingroup$ There were also similar problems in NSolve dealing with elementary functions, see e.g. this post Issue with NSolve. $\endgroup$ – Artes Apr 19 '17 at 14:31
  • 1
    $\begingroup$ NSolve[BesselJ[0, x] == 0 && 0 < x < 20, x, Abracadabra] // Quiet :) $\endgroup$ – Mariusz Iwaniuk Apr 24 '17 at 11:14
13
$\begingroup$

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}}
$\endgroup$
14
$\begingroup$

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

$\endgroup$
  • $\begingroup$ it works in 11.1 $\endgroup$ – Rom38 Apr 18 '17 at 4:35
  • $\begingroup$ 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. $\endgroup$ – Michael E2 Apr 18 '17 at 11:58
  • $\begingroup$ 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). $\endgroup$ – Michael E2 Apr 18 '17 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.