= Solution
Use reproducible random starts and retain the best successful result:
``
rng = np.random.default_rng(2024)
starts = rng.uniform(-4, 4, size=100)
results = [opt.minimize(lambda z: f(z[0]), x0=[x0]) for x0 in starts]
successful = [result for result in results if result.success]
best = min(successful, key=lambda result: result.fun)
print(best.x[0], best.fun)
``
The estimate is \b[$x_{\min}\simeq-0.309213$, $f_{\min}\simeq0.0192409$]. This <random-restart optimization> improves coverage of the different attraction regions, but their number alone does not guarantee global optimality.
Here an analytic check is possible. For $|x|\geq\pi/5$, the envelope gives $f(x)\geq1-e^{-\pi^2/125}\simeq0.0759$, above the candidate. On $[0,\pi/5]$, $f\geq1$. In the remaining interval $[-\pi/5,0]$, the <derivative> condition is equivalent, with $z=-x$, to $\cot(5z)=0.08z$. The left side decreases strictly from $+\infty$ to $-\infty$ while the right side increases, giving one minimum. This certifies the selected well as global rather than relying only on the restart experiment.
Back to article page