# NSolve doesn't find all solutions in a range

In 13.3.1 for Microsoft Windows (64-bit) (July 24, 2023) if I write:

f[x_] := Cos[x] - 0.9999977306829412 + 0.49986470623284673 x^2 - 0.04072419545671301 x^4

sol = NSolve[{f[x] == 0, -π/4 < x < π/4}];

Plot[f[x], {x, -π/4, π/4}, AxesLabel -> {"x", "f(x)"},
Epilog -> {Red, PointSize[Medium], Point[{x, f[x]} /. sol]}]


I get:

where it's clear that NSolve doesn't find two solutions. How can I solve it?

• While I wait for other answers, I'll add that TrigToExp[f[x]] works. Commented Dec 24, 2023 at 9:57
• Mathematica v12.2 keeps the incorrect solutions for all answers! An old bug? Commented Dec 24, 2023 at 11:56

Add Reals.

f[x_] :=
Cos[x] - 0.9999977306829412 + 0.49986470623284673 x^2 -
0.04072419545671301 x^4;
sol = NSolve[f[x] == 0, Reals];
Plot[f[x], {x, -π/4, π/4}, AxesLabel -> {"x", "f(x)"},
Epilog -> {Red, PointSize[Medium], Point[{x, f[x]} /. sol]}]


Solving between -Pi and Pi/2 gives the desired result

sol = NSolve[{f[x] == 0, -Pi < x < Pi/2}];

Plot[f[x], {x, -\[Pi]/4, \[Pi]/4},
AxesLabel -> {"x", "f(x)"},
Epilog -> {Red, PointSize[Medium], Point[{x, f[x]} /. sol]}]