# A puzzling maximization issue using Abs[ ] in the constraints

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.

• Something does seem off: FindMaximum[{x^2 + y^2, Abs[x] <= 1 && Abs[y] <= 1 // PiecewiseExpand[#, {x, y} ∈ Reals] &} // Evaluate, {x, y}] – J. M. is away Apr 11 '17 at 2:27
• 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}]. – JimB Apr 11 '17 at 3:17
• 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. – xzczd Apr 11 '17 at 7:08

## 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 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

• 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? – gwr Apr 11 '17 at 10:01
• Just a side note: The WorkingPrecision -> 30 solution works in v11.1 but not in v9 and v8. – xzczd Apr 11 '17 at 10:12
• @xzczd Good to know, that there really are reasons to update versions. :) – gwr Apr 11 '17 at 10:17