To identify and classify the critical points of the function $f(x,y,z)=x^3+xz^2-3x^2+y^2+2z^2$, I used the Hessian matrix method.
Clear[f, x, y, z];
f = x^3 + x z^2 - 3 x^2 + y^2 + 2 z^2;
cpts = Solve[Grad[f, {x, y, z}] == 0, {x, y, z}, Reals]
This gave me the critical points $(0,0,0)$ and $(2,0,0)$. Then I calculate the Hessian.
H = D[f, {{x, y, z}, 2}];
MatrixForm[H]
Which gave me:
$$\begin{bmatrix} -6+6x & 0 & 2z\\ 0 & 2 & 0\\ 2z & 0 & 4+2z \end{bmatrix}$$
Then I calculated:
Det[H /. {x -> 2, y -> 0, z -> 0}]
Which was 96. Since this is positive, the Hessian method tells me that I must have a local minimum, maximum, or saddle point. Then I did this:
MatrixForm[H /. {x -> 2, y -> 0, z -> 0}]
Which gave me:
$$\begin{bmatrix} 6 & 0 & 0\\ 0 & 2 & 0\\ 0 & 0 & 8 \end{bmatrix}$$
Then the sequence of principal minors is:
$$ 6, \qquad \begin{vmatrix}6 & 0\\0 & 2\end{vmatrix}=12,\qquad\text{and}\qquad\begin{bmatrix}6 & 0 & 0\\0 & 2 & 0\\0 & 0 & 8\end{bmatrix}=96$$
Because they are all positive, we have a local minimum at (2,0,0). A similar test reveals a saddle point at (0,0,0).
My Question: I am now wondering how I might go about doing something in Mathematica to check that I do indeed have a local minimum, giving me some confidence in this method. Maybe something on the saddle point as well? I can't visualize due to the added dimension, but perhaps folks have some other ideas?
Notebook Share: This notebook will give you an idea of what I've written for my students thus far.
FindMinimum and FindMaximum Weird Result?
Trying belisarius and OleksandrR suggestion, I think I am looking at a very strange result:
In[12]:= FindMinimum[{f, (x - 2)^2 + y^2 + z^2 <= 1}, {x, 2}, {y,
0}, {z, 0}]
Out[12]= {-4., {x -> 2., y -> 0., z -> 0.}}
In[14]:= FindMaximum[{f, (x - 2)^2 + y^2 + z^2 <= 1}, {x, 2}, {y,
0}, {z, 0}]
Out[14]= {-4., {x -> 2., y -> 0., z -> 0.}}
Any thoughts or explanation on these results?
Michael E2 Comment Suggestion:
Since I am writing notebooks that have many pages, examples, and sometimes 2, 3, 4, or 5 Manipulate GUIs, I have to protect the content. So here is my adjustment to MichaelE2's wonderful example:
DynamicModule[{f, x, y, z, cpts},
f = x^3 + x z^2 - 3 x^2 + y^2 + 2 z^2;
cpts = {x, y, z} /.
Solve[Grad[f, {x, y, z}] == 0, {x, y, z}, Reals];
Manipulate[
With[{f0 = f /. Thread[{x, y, z} -> cp]},
Show[ContourPlot3D[
f == f0 + level, {x, cp[[1]] - 10^eps, cp[[1]] + 10^eps}, {y,
cp[[2]] - 10^eps, cp[[2]] + 10^eps}, {z, cp[[3]] - 10^eps,
cp[[3]] + 10^eps}, Mesh -> None,
PlotPoints -> ControlActive[9, 25],
ContourStyle -> Opacity[0.7],
PlotLabel ->
Pane[Row[{"f \[Equal]", f0,
Sign[level] /. {-1 -> "-", 0 | 1 -> "+"}, Abs@level}, " "],
100]],
Graphics3D[{
Red, Sphere[cp, .04]
}]
]],
{{level, 0.}, -1., 1., Appearance -> "Labeled"},
{{eps, 0., "zoom"}, -1, Log10[2.], Appearance -> "Labeled"},
{cp, cpts}]]
Adding ContourStyle->Opacity[0.7]
and Graphics3D[{Red, Sphere[cp, .04]}]
also shows the critical point.
NMinimize[f, {x, y, z}]
finds your local minima $\endgroup$FindMinimum
is a better option for local minimization. Here you just happen to be lucky thatNMinimize
fails to find the global minimum. $\endgroup$FindMinimum
:D $\endgroup$