RootSearch is a package for finding all roots within a range from Ted Ersek. As I test it, it is quite robust. But I also encountered some issue that I can not resolve.
I define a function
ClearAll[f];
f[r_?NumericQ] :=
Sort[Re@Eigenvalues[{{3.5` - 1.6` Cos[Im[E^(I 0.) r]] -
2.4` Cos[Re[E^(I 0.) r]], 0, -0.07`, 0}, {0,
3.5` - 2.4` Cos[Im[E^(I 0.) r]] - 1.6` Cos[Re[E^(I 0.) r]],
0, -0.07`}, {-0.07`,
0, -3.5` + 1.6` Cos[Im[E^(I 0.) r]] + 2.4` Cos[Re[E^(I 0.) r]],
0}, {0, -0.07`,
0, -3.5` + 2.4` Cos[Im[E^(I 0.) r]] +
1.6` Cos[Re[E^(I 0.) r]]}}]][[3]]
the plot is quite usual
Now I want to find points where the first derivative of f are zero using RootSearch.
If I do it as
roots = RootSearch[f'[t] == 0, {t, 0., 1.}];
there will be a warning
General::munfl: 2.2204510^-16 2.2250710^-308 is too small to represent as a normalized machine number; precision may be lost.
And no result came out after I waited for several minutes.
However, If I do
roots = RootSearch[f'[t] == 0.0001, {t, 0., 1.}];
It finishes in seconds.
and
vals = Table[{i, f[i]}, {i, Flatten[roots][[;; , -1]]}];
Plot[f[x], {x, 0.1, 1}, PlotRange -> All,
Epilog -> {PointSize[Medium], Red, Point[vals]}]
shows
So, why is RootSearch[f'[t] == 0, {t, 0., 1.}] not working?
I also find as simple as RootSearch[Sin[x] == 0, {x, 0, 100}] will also gives precision lost warning, but it gives result immediately.
PS:
I found that if I change the interval to {0.1,1} then
RootSearch[f'[t] == 0, {t, 0.1, 1.}]
will work. So it is t=0 cause the problem. Why is that?
another much simple case I just found is
ClearAll[g];
g[x_?NumericQ]:=x^3;
and
RootSearch[g'[x] == 0, {x, -1, 1}]
will not give an answer. But
RootSearch[3x^2 == 0, {x, -1, 1}]
gives answer immediately.
This is a valuable case, because Plot based root finding or NDSolve event locating method can not deal with this case( first derivative only touch x axis, not penetrating it)


![plot of f[r]](../../images/fe548819739c220acccbb7a45d177885.webp)
Derivative, just compare:inter = FunctionInterpolation[f[t], {t, 0, 1}, MaxRecursion -> 10]; Plot[{inter'@x, f'[t]}, {x, 0.1, 1}]Other examples: https://mathematica.stackexchange.com/q/29329/1871 https://mathematica.stackexchange.com/q/196998/1871 – xzczd Oct 07 '20 at 13:08NDis controllable withScaleoption. If this post can be solved. I actually will useNDfor my problem for better precision. – matheorem Oct 07 '20 at 13:16RootSearchcorrected in https://mathematica.stackexchange.com/questions/270292/bug-in-rootsearch – Igor Kotelnikov Jul 03 '22 at 06:25