## mathematical optimization – Stopping condition for FindMinimum / FindMaximum

This seems like it should be a simple question — but I am looking to use a “home made” stopping condition with FindMaximum, while evaluating a very complex function.

Printing out the successive changes in the results for my problem (which cannot be boiled down to a quick code sample) I see that the relative differences in about 100 params are on the order of 10^-3 between steps (and often much smaller) which is more than enough for this application — but it just continues to dance around the “right” answer until I hit MaxIterations, and adjusting Precision and Accuracy does not seem to help.

Q: Is there a way to implement a “stopping condition” option for these functions?

## mathematical optimization – Automatic Method for FindMinimum with constraints

``````SystemOptions("FindMinimumOptions")
``````
``````{"FindMinimumOptions" ->
{"DefaultInteriorPointMethod" -> "IPOPT",
``````
``````Reap(FindMinimum({x^2 + y^2, (x - 1)^2 + 2 (y - 1)^2 > 5}, {{x, 4}, {y, 4}},
Method -> "IPOPT", StepMonitor :> Sow({x^2 + y^2, x, y}))) ==
Reap(FindMinimum({x^2 + y^2, (x - 1)^2 + 2 (y - 1)^2 > 5}, {{x,   4}, {y, 4}},
Method -> Automatic, StepMonitor :> Sow({x^2 + y^2, x, y})))
``````
``````True
``````

We can also use `"IPOPT"` as the value for `"Method"` suboption of the option `Method`:

``````Reap(FindMinimum({x^2 + y^2, (x - 1)^2 + 2 (y - 1)^2 > 5}, {{x, 4}, {y, 4}},
Method -> Automatic, StepMonitor :> Sow({x^2 + y^2, x, y}))) ==
Reap(FindMinimum({x^2 + y^2, (x - 1)^2 + 2 (y - 1)^2 > 5}, {{x, 4}, {y, 4}},
Method -> {Automatic, "Method" -> "IPOPT"}, StepMonitor :> Sow({x^2 + y^2, x, y})))
``````
``````True
``````

Using the option setting `Method -> {Automatic, "Method" -> "NonlinearInteriorPoint"}` gives the same result as `Method -> "InteriorPoint"`:

``````Reap(FindMinimum({x^2 + y^2, (x - 1)^2 + 2 (y - 1)^2 > 5}, {{x, 4}, {y, 4}},
Method -> "InteriorPoint", StepMonitor :> Sow({x^2 + y^2, x, y}))) ==
Reap(FindMinimum({x^2 + y^2, (x - 1)^2 + 2 (y - 1)^2 > 5}, {{x, 4}, {y, 4}},
Method -> {Automatic, "Method" -> "NonlinearInteriorPoint"},
StepMonitor :> Sow({x^2 + y^2, x, y})))
``````
`````` True
``````

## plotting – FindMinimum with Manipulate

I have an expression for the energy of a given physical system and I need to plot its minimum with respect to one of the parameters while the others are allowed to vary.

The expression is the following:

``````energy(c_,(Sigma)_,k_,(CapitalLambda)_,p2_,(CapitalDelta)_,(CapitalGamma)_):=c/(2 (Sigma)^2) - (k*(CapitalLambda))^2/ 2*(CapitalDelta)/((CapitalDelta)^2 + (CapitalGamma)^2/4)*p2*c - (Pi) (k*(CapitalLambda))^2*(CapitalDelta)*(Sigma)^2*p2*PolyLog(2, -(c/(2 *((CapitalDelta)^2 + (CapitalGamma)^2/4)*(Pi)*(Sigma)^2)));
``````

I want to plot this expression for the value of $$sigma$$ (I start from a small value in FindMinimum, for instance, $$10^{-6}$$ in order to avoid the zero) which makes it minimum while $$p$$ and $$Delta$$ are allowed to vary. The remaining variables have definite values. In my attempts, I have tried the following:

``````Manipulate(Plot(FindMinimum(energy(7*10^6, (Sigma), 8.055*10^6, 0.0000659176, p, (CapitalDelta), 1), {(Sigma), 10^-6})((2)), {p, 0, 10}), {(CapitalDelta), 10^-6, 1000})
``````

When I run this last line, it gives me the manipulate plot. Nevertheless, it does return the following mistakes:

FindMinimum: The line search decreased the step size to within the tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the function. You may need more than MachinePrecision digits of working precision to meet these tolerances

and

General: “Further output of FindMinimum::lstol will be suppressed during this calculation.”

I am not sure this is the correct way to achieve what I need, so I wonder if anyone may shed some light on this problem.

## mathematical optimization – Retrieve Lagrange multipliers FindMinimum

I am using `FindMinimum` to compute numerically a local minimum of a nonlinear finite dimensional optimization problem with constraints.
The method converges and the result is relevant.

However I would like to retrieve Lagrange multipliers associated the constraints, how can I do that ?

## mathematical optimization – Wierd behaviour of FindMinimum

On Mathematica 12.1, Try

``````FindMinimum[Sin[x] + 1, {x, 55.00000000000001`, 54, 56},  Method -> "PrincipalAxis"]
``````

It will output

FindMinimum::fddis: The starting values 55.00000000000001` and 55.`
are not sufficiently distinct to begin a search.

FindMinimum::fddis: The starting values 55.00000000000001` and 55.`
are not sufficiently distinct to begin a search.

FindMinimum::fddis: The starting values 55.00000000000001` and 55.`
are not sufficiently distinct to begin a search.

General::stop: Further output of FindMinimum::fddis will be suppressed
during this calculation.

and no result returned.

However,

``````FindMinimum[Sin[x] + 1, {x, 55.0000000000000`, 54, 56}, Method -> "PrincipalAxis"]
``````

has no problem to get

``````{0., {x -> 54.9779}}
``````

What is wrong?

## math optimization – How do I get FindMinimum to give me the right answer the first time I call it?

I am trying to minimize the Chi Square error on a complex function. The first time I run FindMinimum I get a response that is close to the overall minimum, the second time I run it, with the results of the first pass, I get a better response (note the results below). How do you do this in one pass?

``````result = FindMinimum({chiSquared(ber, btm, dsr, dcd),
0 < ber && 0 < btm && 0 < dsr && 0 < dcd}, {{ber, 1.}, {btm,
10^10}, {dsr, 1.}, {dcd, 1000}})

Out(402)= {1603.9032996720166, {ber -> 0.30175546158546906,
btm -> 8.984265873668348*^9, dsr -> 3.114204410911019,
dcd -> 1100.9245439266256}}

In(403):= result =
FindMinimum({chiSquared(ber, btm, dsr, dcd)}, {{ber,
OptionValue(result((2)), ber)}, {btm,
OptionValue(result((2)), btm)},
{dsr, OptionValue(result((2)), dsr)}, {dcd,
OptionValue(result((2)), dcd)}})

Out(403)= {1558.845892206124, {ber -> 0.4090451007924997,
btm -> 1.1343566072120678*^10, dsr -> 3.4512578697898606,
dcd -> 928.6070747021281}}
``````

## Mathematical Optimization – FindMinimum with conditions gives infinite expressons although I've used conditions to exclude them

I want to find the minimum of a function and I have conditions to this function. One of the conditions could give $$frac {1} {0}$$ and, therefore, I add another condition to exclude it.

See for example:

``````FindMinimum({a/b, 1/(1 - c)^2 > 0 && c > 2}, {a, b, c})
``````

This gives the following error:

Power :: infy: Infinite Expression 1 / 0. ^ 2 met.

and

FindMinimum :: nrlnum: The value of the function {ComplexInfinity} is not a
list of real numbers of dimensions {1} in {a, b, c} = {1., 1., 1.}.

I have looked for similar errors but they are related to conditional expressions and therefore do not really help me here.

## numerics – Can I trust FindMinimum

I have a function $$f (x, y)$$ For who `Minimum({f( x, y), x > 0, y > 0}, {x, y})` can not find a solution. however, `FindMinimum({f( x, y), x > 0, y > 0}, {x, y})` reveals that the minimum is at $$(x_1, y_1)$$ and $$f (x_1, y_1)> 0$$.

The first function tries to find an analytical solution, while the second only identifies numerical solutions, if I am right.

Can I be (analytically) sure that $$f (x, y)> 0$$ for everyone $$x> 0, y> 0$$?

## mathematical optimization – FindMinimum where the variables are integers

I wish to find the minimum of a function where the variables are integers. Here is an example of simple minimum work (my actual function is much more complicated).

``````ClearAll(f);
f({i1_, i2_}) := N(Total(1 + Sin(#) & /@ {i1, i2}));

FindMinimum({f({i1, i2}),
0 < i1 < 11 && 10 < i2 < 21 && {i1, i2} (Element) Integers}, {{i1,
5}, {i2, 15}})
``````

The result is an error message stating that integers are only allowed for linear programming.

Is there a technique to solve this type of problem? Thank you

## mathematical optimization – FindMinimum does not correctly perform the iterations during an iteration, but funciton correctly evaluates the values ​​chosen in the stack trace

I have an objective function that I have the intention to minimize with FindMinimum. I chose a starting point for iteration and execute the code. But Mathematica generates an error after 3 iterations: my function returns a complex number. But, when I check the stack trace and substitute the values ​​for which the function returns complex, I only get real values. Someone knows what could be the reason?
This is the error displayed:

This is the trace of the pile:

I've tried to evaluate the complex function as shown in the stack trace, but it only gives real values: