Extrema on the edge.
f = x^2 - x + 2 y^2;
g = x^2 + y^2 - 1;
L = f + \[Lambda] g;
pts = Solve[{Grad[L, {x, y}] == 0, g == 0}, {x, y, \[Lambda]}];
points = pts[[All, 1 ;; 2]];
critpts = Thread@{f /. points, points};
bordered Hessian:
hesseMatrix = {{0, D[g, x], D[g, y]}, {D[g, x], D[L, x, x],
D[L, x, y]}, {D[g, y], D[L, y, x], D[L, y, y]}} /. pts;
detHesse = Det /@ hesseMatrix
{-4, 6, 6, -12}
max = Cases[Thread@{Sign /@ detHesse, critpts}, {1, _}][[All, 2]];
min = Cases[Thread@{Sign /@ detHesse, critpts}, {-1, _}][[All, 2]];
sol = Association["Minima" -> min, "Maxima" -> max]
Extrema within the region.
sol2 = Solve[{Grad[f, {x, y}] == 0, x^2 + y^2 < 1}, {x, y}];
globalMin = Thread@{f /. sol2, sol2}
Eigenvalues@D[f, {{x, y}, 2}] /. sol2
{4, 2}
Eigenvalues are positive; this is the global minimum.
reg = ImplicitRegion[x^2 + y^2 <= 1, {x, y}];
Show[
Plot3D[f, {x, y} \[Element] reg, Mesh -> 10,
MeshFunctions -> {#^2 + #2^2 &}, PlotTheme -> "FilledSurface"],
Graphics3D[{
Red, [email protected], Point[{x, y, f} /. sol["Minima"][[All, 2]]],
Green, [email protected], Point[{x, y, f} /. sol["Maxima"][[All, 2]]],
Blue, [email protected], Point[{x, y, f} /. globalMin[[1, 2]]]}]
]
FindMinimum
usually does what is required. What do you mean by exact? $\endgroup$Reduce[{D[x^2 - x + 2*y^2 D[x^2 - x + 2*y^2, x] == 0, x] == 0, D[x^2 - x + 2*y^2, y] == 0, x^2 + y^2 <= 1}, {x, y}, Reals]
. Its behavior on the boundary should be studied separately. $\endgroup$FindMinimum
might also find a global min and miss local ones. To get all of them in some region one can set up a KKT solver. $\endgroup$