I need to minimize a function that has several problem points (divergences).

For example, if I consider:

f[xx_] := Limit[Sin[x]/x, x -> xx];
FindMinimum[{f[xx], 5 >= xx && xx >= -5}, {xx, 0}]

The FindMinimum falls due to the divergence that exists at x = 0 and does not consider the limit of the function.

Is there any function to do that?. I have thought about using NMinimize but I don't know if it will be as effective as FindMinimum.

The sin (x) / x function was an example, the function I have to evaluate has multiple repairable divergences whose points I don't know.

I tried the following but it doesn't work either:

ff[x_] := Sin[x]/x;

g[xx_] := Piecewise[{{Limit[ff[x], x -> xx], SameQ[ff[xx], Indeterminate]}, {ff[xx], NumericQ[ff[xx]] == True}}]

FindMinimum[g[xx], {xx, 0}]

It does not yield a value, findfinimum fails


2 Answers 2


I would recommend using the built-in Sinc[] function as it already knows that Sinc[0] == 1.

Most (I imagine all) minimization routines are sensitive to the starting point. If you give them a bad starting point, you're going to get a bad result. The point x = 0 is pretty much the worst possible starting point for most algorithms because of the shape of the Sinc function. There are a number of possible solutions:

FindMinimum[Sinc[x], x]
FindMinimum[{Sinc[x], -5 <= x <= 5}, {x, 1}]
NMinimize[Sinc[x], x]

All of these return either {-0.217234, {x -> -4.49341}} or {-0.217234, {x -> 4.49341}} which are the two, identical minima.


Only define the function in the limit at the singular points.

f[x_ /; x == 0] = Limit[Sin[x]/x, x -> 0]; 

f[x_] := Sin[x]/x;

sol1 = FindMinimum[{f[x], -5 <= x <= 5}, x]

(* {-0.217234, {x -> 4.49341}} *)


sol2 = NMinimize[{f[x], -5 <= x <= 5}, x]

(* {-0.217234, {x -> -4.49341}} *)

The different results are equivalent since

f[x] == f[-x]

(* True *)

Note that the symbolic evaluation is only possible because the definition of f is not restricted to numeric arguments.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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