- If $D f(x,y)=0$ and $\mathrm{Hessian}f(x,y)$ is a positive definite matrix,then $f(x,y)$ get the local minimal.
- If $D f(x,y)=0$ and $\mathrm{Hessian}f(x,y)$ is a negative definite matrix,then $f(x,y)$ get the local minimal.
We use Grad[f[x,y],{x,y}]
or D[f[x,y],{{x,y},1}]
and D[f[x,y],{{x,y},2}
to calculate the Gradient and Hessian.
And we know that a matrix A={{a,b},{c,d}}
is positive definite if a>0
and Det[A]>0
, and a matrix A={{a,b},{c,d}}
is negative definitee if a<0
and Det[A]>0
.
Clear[f, localmin, localmax];
f[x_, y_] = x^3 - 2 y^3 - 3 x + 6 y;
localmin =
Solve[{D[f[x, y], {{x, y}, 1}] == 0,
Det[D[f[x, y], {{x, y}, 2}][[;; 1, ;; 1]]] > 0,
Det[D[f[x, y], {{x, y}, 2}][[;; 2, ;; 2]]] > 0}, {x, y}];
localmax =
Solve[{D[f[x, y], {{x, y}, 1}] == 0,
Det[D[f[x, y], {{x, y}, 2}][[;; 1, ;; 1]]] < 0,
Det[D[f[x, y], {{x, y}, 2}][[;; 2, ;; 2]]] > 0}, {x, y}];
Show[Plot3D[f[x, y], {x, -2, 2}, {y, -2, 2}],
Graphics3D[{AbsolutePointSize[20], {Blue,
Point[{x, y, f[x, y]}] /. localmin}, {Red,
Point[{x, y, f[x, y]}] /. localmax}, Arrowheads[.02],
Arrow[{# + {0, 0, 10}, #} &@{x, y, f[x, y]} /. localmin],
Text["local min", {x, y, f[x, y]} + {0, 0, 10} /. localmin,
Background -> Yellow],
Arrow[{# + {0, 0, 10}, #} &@{x, y, f[x, y]} /. localmax],
Text["local max", {x, y, f[x, y]} + {0, 0, 10} /. localmax,
Background -> Yellow]}], PlotRange -> All]

FindMaximum[{x^3 - 2 y^3 - 3 x + 6 y, -5 <= x <= 5, -5 <= y <= 5}, {x,
y}]
FindMinimum[{x^3 - 2 y^3 - 3 x + 6 y, -5 <= x <= 5, -5 <= y <= 5}, {x,
y}]
{6., {x -> -1., y -> 1.}}
{-6., {x -> 1., y -> -1.}}
Plot3D[x^3 - 2 y^3 - 3 x + 6 y, {x, 0, 2}, {y, 0, 2}]
It is always a good idea to plot the given functions to ge an overview. $\endgroup$Solve[Thread[D[x^3 - 2 y^3 - 3 x + 6 y, {{x, y}}] == 0], {x, y}]
yields{{x -> -1, y -> -1}, {x -> 1, y -> -1}, {x -> -1, y -> 1}, {x -> 1, y -> 1}}
Plot3D[x^3 - 2 y^3 - 3 x + 6 y, {x, -2, 2}, {y, -2, 2}]
$\endgroup$