8
$\begingroup$

Consider the following pair of commands.

Maximize[{x^2 + y^2, Abs[x] <= 1, Abs[y] <= 1}, {x, y}]

$\{2, \{x \rightarrow -1, y \rightarrow -1\}\}$

FindMaximum[{x^2 + y^2, Abs[x] <= 1, Abs[y] <= 1}, {x, y}]

$\{ 8.63643\times 10^{-21}, \{x \rightarrow -6.57131\times 10^{-11}, y \rightarrow -6.57131\times10^{-11}\}\}$

Now, I understand that FindMaximum[] is only looking for a local maximum, but what it finds is not that either. Any thoughts? Is it something about Abs[]?

EDIT Just to clarify in response to J.M.'s wise commentary, just using && instead of a comma between the constraints makes no difference, though the full PiecewiseExpand[] does.

$\endgroup$
  • 2
    $\begingroup$ Something does seem off: FindMaximum[{x^2 + y^2, Abs[x] <= 1 && Abs[y] <= 1 // PiecewiseExpand[#, {x, y} ∈ Reals] &} // Evaluate, {x, y}] $\endgroup$ – J. M. is away Apr 11 '17 at 2:27
  • 3
    $\begingroup$ It seems to go wacko only when 1 is used. It works fine with any other number (not that I've tried them all): FindMaximum[{x^2 + y^2, Abs[x] <= 99999/100000 && Abs[y] <= 99999/100000}, {x, y}] and FindMaximum[{x^2 + y^2, Abs[x] <= 2 && Abs[y] <= 2}, {x, y}]. $\endgroup$ – JimB Apr 11 '17 at 3:17
  • 1
    $\begingroup$ I guess Limitations of the Interior Point Method section of this tutorial is related. Also, notice if one uses RealAbs instead of Abs, or manually setting Gradient -> "FiniteDifference", the warning FindMaximum::eit pops up. $\endgroup$ – xzczd Apr 11 '17 at 7:08
4
$\begingroup$

Starting Point Issues

The problem here seems to be the choice of the starting points as can be seen from these "studies":

(* The original Problem" *)
pts["AbsNoStartPts"]  pts["AbsNoStartPts"] = Reap[
    FindMaximum[ 
        {x^2 + y^2, Abs[x] <= 1 && Abs[y] <= 1}, 
        {x, y}, 
        StepMonitor :> Sow[{x, y}]
    ]
][[2, 1]];

(* using inequalities without starting points *)
pts["InequalityNoStartPts"] = Reap[
    FindMaximum[ 
        {x^2 + y^2, -1 <= x <= 1 && -1 <= y <= 1}, 
        {x, y}, 
        StepMonitor :> Sow[{x, y}]
    ]
][[2, 1]];

(* the original problem using a starting point not too close to zero *)
pts["AbsStartPts"] = Reap[
    FindMaximum[ 
        {x^2 + y^2, Abs[x] <= 1 && Abs[y] <= 1}, 
        { { x, 0.1 } , { y, 0.1 } }, 
        StepMonitor :> Sow[{x, y}]
    ]
][[2, 1]];

Now, we can see how the solver gets stuck once one starting value for either $x$ or $y$ is very close or equal to zero:

Map[
    ContourPlot[
        x^2 + y^2, 
        {x, -1, 1}, {y, -1, 1}, 
        PlotLabel -> #, 
        Epilog -> { Red, Line[pts[#]], Point[pts[#]] }, 
        ImageSize -> Small] &,
    {"InequalityNoStartPts", "AbsNoStartPts","AbsStartPts"}
] // Row

Initial Point Dependencies

The issue is the lack of a clear gradient it seems if one component is too close to zero. Next to providing starting points for FindMinimum in more recent Versions of Mathematica (thank you, xzczd, for this information) we may simply increase the WorkingPrecision:

FindMaximum[
    {x^2 + y^2, Abs[x] <= 1 && Abs[y] <= 1}, 
    {x, y}, 
    WorkingPrecision -> 30
]//First // Round

2

$\endgroup$
  • $\begingroup$ Maybe somebody can give a good reason for the starting points being different when using Abs instead of the inequality? As always the Mathematica Navigator (still) is an invaluable source of information here. Using NMaximize may prove to be more robust than using FindMinimum? $\endgroup$ – gwr Apr 11 '17 at 10:01
  • 1
    $\begingroup$ Just a side note: The WorkingPrecision -> 30 solution works in v11.1 but not in v9 and v8. $\endgroup$ – xzczd Apr 11 '17 at 10:12
  • 1
    $\begingroup$ @xzczd Good to know, that there really are reasons to update versions. :) $\endgroup$ – gwr Apr 11 '17 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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