As a simple example let's consider the function $f(x) = x \left(1-\frac{x}{3}\right) \left(\frac{x}{10}-1\right)$:
f[x_] := x (1-x/3) (x/10-1)
I want to find, $r(c)$, the root of the function $f(x)+c$ that is closer to $0$ for $c\in[0,1]$.
The value of the local minimum of $f$ is $c_{\text{min}}=-0.642389\dots$, this implies that for $c\le -c_{\text{min}}$, $r(c) < 1.38$ and for $c > -c_{\text{min}}$, $r(c) > 10.25$.
The problem of course is that if I call FindRoot
with $0$ as the initial point,for $c=-c_{\text{min}}+\varepsilon$ the function $f(x)+c$ come close to the $x$ axis and the algorithm takes too long to converge.
Is there any way to tell mathematica that if it takes too long to find a root starting at 0, it should instead start at 10?
I would like to be able to plot the discontinuous function $r(c)$.
NSolve[eq, x, Reals]
and analyze the root closest to zero. Might depend on how complicated your actual $f(x)$ is. $\endgroup$