\section{Critical Points}
In this section, we assume that $f : D \rightarrow \mathbb{R}$ where $D \subset \mathbb{R}^n$ is a domain.  For a point $\mathbf{a} \in \mathbb{R}^n$, we say that:
\begin{itemize}
\item $f$ has a \underline{local minimum} at $\mathbf{a}$ if there is a neighbourhood $U$ of $\mathbf{a}$ such that $f (\mathbf{x}) \geq f (\mathbf{a})$ for all $\mathbf{x} \in U \cap D$. 

\medskip

\item $f$ has a \underline{global minimum} at $\mathbf{a}$ if $f(\mathbf{x}) \geq f (\mathbf{a})$ for all $\mathbf{x} \in D$.

\medskip

\item a \underline{local/global maximum} follows similar definitions, but with $f (\mathbf{x}) \leq f (\mathbf{a})$.
\end{itemize}

Local maxima and minima can be characterized in terms of the gradient of $f$.

\begin{theorem}[Necessary Conditions for Maxima/Minima]
Suppose that $f : D \rightarrow \mathbb{R}$ has a local minimum or maximum at $\mathbf{a} \in D$. Then at least one of the following holds:
\begin{enumerate}
\item $\nabla f (\mathbf{a}) = \mathbf{0}$; this is a \underline{critical point} of $f$;

\smallskip

\item $\nabla f (\mathbf{a})$ does not exist; this is a \underline{singular point} of $f$;

\smallskip

\item the point $\mathbf{a}$ is a boundary point of the domain $D$.
\end{enumerate}
\end{theorem}

\begin{proof}[Proof for two-variable functions]
Suppose $f$ has a local minimum or maximum at $(a,b)$, that $(a,b)$ is not on the boundary of $D$ (so there is a neighbourhood $U$ of $(a,b)$ which is entirely contained in $D$), and further suppose that $\nabla f (\mathbf{a})$ exists. 

\medskip
Consider the function $f(x,b)$ of one variable. This function is defined on some interval of $x$ values around $a$ and must have a local minimum/maximum at $a$.  This follows since, for all $x$ close enough to $a$, we have
$$
f(x,b) \geq f(a,b) \textrm{ if } f \textrm{ has a minimum}
$$
$$
f(x,b) \leq f(a,b) \textrm{ if } f \textrm{ has a maximum}
$$
Further, since we have assumed that $\nabla f (\mathbf{a})$ exists, we know that $\frac{\partial}{\partial x} f(x,b) \vert_{x=a}$ exists. Therefore, by one variable calculus, we know that $f_{x} (a,b) = 0$.  A similar argument considering the function $f(a,y)$ shows that $f_{y} (a,b) = 0$.  Therefore, $\nabla f (a,b) = \mathbf{0}$, as claimed.
\end{proof}


\begin{figure}[H]\label{41fig1}
\centering
\includegraphics[width= .8\textwidth]{41fig1.png}
\caption{In the neighbourhood $U$ of $(a,b)$,  we examined the single-variable functions $f(x,b)$ and $f(a,y)$, which are defined on the coordinate axes as depicted above.}
\end{figure}


\subsection{Classification of Critical Points} For the rest of this section, we assume that the 
function $f(x,y)$ has a critical point at $(a,b)$ and is $C^2$ on some neighbourhood of this point. 
We first note that $f$ can behave in several different ways--not just having a maximum or minimum. Three representative examples are given in Figure \ref{41fig:main}.



\begin{figure}
\begin{minipage}{\linewidth}
\centering
\subfloat[]{\label{main:a}\includegraphics[width = .5\linewidth]{41fig2.png}}
\end{minipage}\par\medskip
\begin{minipage}{\linewidth}
\centering
\subfloat[]{\label{main:b}\includegraphics[width = .5\linewidth]{41fig3.png}}
\end{minipage}\par\medskip
\begin{minipage}{\linewidth}
\centering
\subfloat[]{\label{main:c}\includegraphics[width = .5\linewidth]{41fig4.png}}
\end{minipage}

\caption{Each of the three surfaces above has a critical point at the origin $(0,0,0)$. At that point, they have a minimum, maximum and saddle point, respectively.  The equations are given by $z = x^2 + y^2$,  $z = -(x^2 + y^2)$, and $z = y^2 - x^2$.}
\label{41fig:main}
\end{figure}

\medskip


We can use Taylor's second order polynomial $p_2 (x,y)$ to classify such behaviour. Suppose $f (\mathbf{x})$--with $\mathbf{x} = (x_1,...,x_n)$--has a critical point at $\mathbf{a}$. Then, near $\mathbf{a}$ we have the approximation
$$
f (\mathbf{x}) \approx f (\mathbf{a}) + \nabla f (\mathbf{a}) \cdot (\mathbf{x} - \mathbf{a}) + \frac{1}{2} (\mathbf{x} - \mathbf{a}) \cdot \mathscr{H}f (\mathbf{x} - \mathbf{a})^t.
$$
However, because $\mathbf{a}$ is a critical point, we have $\nabla f (\mathbf{a}) = \mathbf{0}$.  Thus the main non-constant term in the approximation comes from the Hessian matrix.  Recall that
$$
\mathscr{H} f=
\begin{pmatrix}
f_{11} & f_{12} & \cdots & f_{1n} \\
\cdots & \cdots & \cdots & \cdots \\
f_{n1} & f_{n2} & \cdots & f_{nn}
\end{pmatrix}
$$
If $f$ is $C^2$ near $\mathbf{a}$, then the error terms satisfy 
\begin{equation}\label{41-eq-error}
|f (\mathbf{x}) - p_2 (\mathbf{x})|=o(|\mathbf{x} - \mathbf{a}|^2).
\end{equation}
Let $Q (\mathbf{x}) = \frac{1}{2} (\mathbf{x} - \mathbf{a}) \cdot \mathscr{H} f(\mathbf{x} - \mathbf{a})^t$. Consider the following cases:
\begin{enumerate}
\item Suppose that $Q (\mathbf{x}) > 0$ for all $\mathbf{x} \neq \mathbf{a}$. (In the language of algebra, $\mathscr{H}f$ is a positive definite matrix; see your textbook for more about that.) Then $$f(\mathbf{x}) \approx f (\mathbf{a}) + Q (\mathbf{x}) \geq f (\mathbf{a})$$ for all $\mathbf{x}$ sufficiently close to $\mathbf{a}$. Hence the function $f (\mathbf{a}) + Q (\mathbf{x})$ has a local minimum at $\mathbf{a}$. The estimate (\ref{41-eq-error}) guarantees that the same is true for the original function $f(\mathbf{x})$ (exercise: prove this!).


(Note: if $\mathbf{x}$ is not so close to $\mathbf{a}$ then the error terms $f (\mathbf{x}) - p_2 (\mathbf{x})$ may be very large, so that Taylor's approximation cannot be used to determine whether $f$ has a global maximum or minimum at $\mathbf{a}$.)

\medskip

\item Suppose $Q (\mathbf{x}) < 0$ for all $\mathbf{x} \neq \mathbf{a}$. (In the language of algebra, $\mathscr{H}f$ is negative definite.) Then, 
$$
f (\mathbf{x}) \approx f (\mathbf{a}) + Q(\mathbf{x}) \leq f (\mathbf{a})
$$
for all $\mathbf{x}$ close enough to $\mathbf{a}$. Hence, $f (\mathbf{a}) + Q(\mathbf{x})$ has a local maximum at $\mathbf{a}$. By (\ref{41-eq-error}), so does $f$.

\medskip

\item It could also happen that, in every neighbourhood of $\mathbf{a}$, $Q (\mathbf{x}) $ takes both positive and negative values.
That is, there may be points $\mathbf{x} \neq \mathbf{y}$ near $\mathbf{a}$ such that $Q (\mathbf{x}) > 0$ and $Q (\mathbf{y}) < 0$--which means that $\mathscr{H}f$ is indefinite.  In this case, $f$ has a saddle point at $\mathbf{a}$.
\end{enumerate}

The functions $f(x,y) = x^2 + y^2$, $g(x,y) = -x^2 - y^2$, and $h(x,y) = y^2 - x^2$  in Figure \ref{41fig:main} are examples of situations $(1)$, $(2)$, and $(3)$, respectively, with $\mathbf{a}= (0,0)$. 

\begin{remark}
Notice that this does not cover all cases. For example, we could have $Q (\mathbf{x}) \geq 0$ for all $\mathbf{x} \neq \mathbf{a}$ and $Q (\mathbf{x}) = 0$ for some $\mathbf{x} \neq \mathbf{a}$. In this case, $Q (\mathbf{x})$ is \underline{positive semidefinite} but not positive definite. In such cases, the behaviour of $f$ near $\mathbf{a}$ also depends on the errors $f(\mathbf{x}) - p_2 (\mathbf{x})$.  As such, it cannot be determined just based on the second order derivatives of $f$. Take a look at the graphs of $f_{\pm} (x,y) = x^2 \pm y^4$ in Figure \ref{41fig:main-b}. Both of the functions $f_\pm$ have the same second order approximation $p_2(x,y)=x^2$ near $(0,0)$.
\end{remark}



\begin{figure}

\begin{minipage}{.5\linewidth}
\centering
\subfloat[]{\label{main:a-b}\includegraphics[width = .9\linewidth]{41fig5.png}}
\end{minipage}%
\begin{minipage}{.5\linewidth}
\centering
\subfloat[]{\label{main:b-b}\includegraphics[width = .9\linewidth]{41fig6.png}}
\end{minipage}\par\medskip

\caption{The surfaces $f_+ (x,y) = x^2 + y^4$ and $f_- (x,y)  = x^2 - y^4$ are shown in the above figures $(A)$ and $(B)$, respectively.  The associated Hessian matrices are positive semi-definite (for $(A)$) and negative semi-definite (for $(B)$). }
\label{41fig:main-b}
\end{figure}

\subsection{Determining the behaviour of $\mathscr{H}f$}
In order to determine whether $\mathscr{H}f$ is positive/negative definite, indefinite or neither, we must consider the determinants of the \underline{principal minors} of $\mathscr{H}f$. These are the determinants of the sub-matrices, which are given by
$$
D_1 = f_{11}, \quad 
D_2 =
\begin{vmatrix}
f_{11} & f_{12} \\
f_{21} & f_{22}
\end{vmatrix}
\quad
D_3 =
\begin{vmatrix}
f_{11} & f_{12} & f_{13} \\
f_{21} & f_{22} & f_{23} \\
f_{31} & f_{32} & f_{33}
\end{vmatrix},
\textrm{ etc. }
$$
We have the following conditions categorizing the behaviour of the Hessian matrix:
\begin{itemize}
\item If $D_1 > 0, D_2 > 0, D_3 > 0,..., D_n > 0$ then $\mathscr{H}f$ is positive definite, so that $f$ has a \underline{local minimum} at $\mathbf{a}$.

\medskip

\item If the principal minors $D_1,...,D_n$ satisfy $D_j < 0$ whenever $j$ is odd and $D_k > 0$ whenever $k$ is even, then $\mathscr{H}f$ is negative definite, which implies that $f$ has a \underline{local maximum} at $\mathbf{a}$.

\medskip

\item If $D_n = \det (\mathscr{H}f) \neq 0$ but the sign sequence of the principle minors is anything other than $+,+,...,+$ or $-,+,-,...$ then $\mathscr{H}f$ is indefinite, which implies that $f$ has a \underline{saddle point} at $\mathbf{a}$.

\medskip

\item However, if $D_n = \det (\mathscr{H}f) = 0$, then the test is inconclusive, and so we cannot decide the type of critical point at $\mathbf{a}$ just from the Hessian matrix $\mathscr{H}f$.
\end{itemize}

\subsection{Why does the test work?}
We start with an important special case. Assume that the Hessian matrix is diagonal, so that
$$
\mathscr{H} f=
\begin{pmatrix}
\lambda_1 & 0 & 0 & \cdots & 0 \\
0 & \lambda_2 & 0 & \cdots & 0 \\
0 & 0 & \lambda_3 & \cdots & 0 \\
\cdots & \cdots & \cdots & \cdots & \cdots \\
0 & 0 & 0 & \cdots & \lambda_n
\end{pmatrix}
$$
This means that $f_{11} (\mathbf{a}) = \lambda_1, f_{22} (\mathbf{a}) = \lambda_2,...,f_{nn} (\mathbf{a}) = \lambda_n$ and $f_{ij} (\mathbf{a}) = 0$ for $i \neq j$. Then, the second order Taylor polynomial is given by
$$
p_2 (\mathbf{x}) = \underbrace{\frac{1}{2} \big[\lambda_1 (x_1 - a_1)^2 + \lambda_2 (x_2 - a_2)^2 + \cdots + \lambda_n (x_n - a_n)^2 \big]}_{Q(\mathbf{x})=Q(x_1,...,x_n)} + f(\mathbf{a})
$$
Note also that
$$
D_1=\lambda_1,\ D_2=\lambda_1\lambda_2,\ \dots,\ D_n=\lambda_1\lambda_2\cdots\lambda_n.
$$
Now, consider the sign of $Q(\mathbf{x})$:
\begin{itemize}
\item If $\lambda_j > 0$ for all $j$, then $Q(\mathbf{x}) > 0$ for all $\mathbf{x} \neq \mathbf{a}$.  This gives a local minimum. We also have the $++++...$ pattern for the $D_1,\dots,D_n$ sequence.

\medskip

\item If $\lambda_j < 0$ for all $j$, then $Q(\mathbf{x}) < 0$ for all $\mathbf{x} \neq \mathbf{a}$, so that we have a local maximum.
In terms of principal minors, we get $D_1 = \lambda _1 < 0$, $D_2 = \lambda_1 \lambda_2 > 0$, $D_3 = \lambda_1 \lambda_2 \lambda_3 < 0$, and so on. This corresponds to the $-+-+...$ pattern.  

\medskip

\item If $\lambda_j \neq 0$ for all $j$ (so that $\det (\mathscr{H}f) = \lambda_1 \cdots \lambda_n \neq 0)$ but the sign of the $\lambda_j$ is not constant, then some of the $\lambda_j (x_j - a_j)^2$ terms are positive and others are negative for $x_j\neq a_j$, so that the function has a ``directional minimum" in some directions and a ``directional maximum" in other directions. This implies a saddle point.

\smallskip
\noindent
(In particular, the $+-+-...$ pattern does not work the same way as $-+-+...$! With a $+-+-...$ pattern, we would have $\lambda_1>0$ and $\lambda_2<0$, so that $\mathscr{H}f$ is indefinite.)



\medskip

\item If $\lambda_j = 0$ for some $j$, then the error terms may be large (in some direction) relative to the size of $Q (\mathbf{x})$, so that the test is inconclusive. 
\end{itemize}


When $\mathscr{H}f$ is not necessarily diagonal, we can always perform a linear change of variables which reduces to the diagonal case. Specifically, let $A$ be a symmetric $n\times n$ matrix; then there is an orthogonal matrix $Q$ and a diagonal matrix $D$, both $n\times n$, such that $A=Q^{-1}DQ$. (This should be covered in your co-requisiite linear algebra course at some point.) The matrix $Q$ provides the needed change of variables. 



\section*{Worked Problems}
\begin{enumerate}[1.]
\item {\it Find and classify the critical points of the function $f(x,y) = x + y - x^2y - x y^2$.}

\medskip

We proceed in two steps:

\medskip

\begin{itemize}
\item The first order partials are $f_x (x,y) = 1 - 2xy - y^2$ and $ f_y (x,y) = 1 - 2xy - x^2$.
To find critical points, we must set $f_x = f_y = 0$, which gives:
$$
x^2 = y^2 \Rightarrow x = \pm y.
$$
If we set $x = y$,  then,
$$
1 - 2x^2 - x^2 = 0 \Rightarrow 1 - 3x^2 = 0 \Rightarrow x = \pm \frac{1}{\sqrt{3}}.
$$
If $x = - y$, we have
$$
1 + 2x^2 - x^2 = 1 + x^2 = 0
$$
which has no solutions.  The critical points are $(\frac{1}{\sqrt{3}},\frac{1}{\sqrt{3}})$ and $(-\frac{1}{\sqrt{3}}, -\frac{1}{\sqrt{3}})$.

\smallskip

\item To classify the critical points, we evaluate the Hessian matrix at each point. First, the second order derivatives are
$$
f_{xx} (x,y) = -2y, f_{xy} = f_{yx} = -2x - 2y, f_{yy} (x,y) = -2x.
$$
So, at $(\frac{1}{\sqrt{3}},\frac{1}{\sqrt{3}})$, we have
$$
\mathscr{H}f =
\begin{pmatrix}
- \frac{2}{\sqrt{3}} & -\frac{4}{\sqrt{3}} \\
- \frac{4}{\sqrt{3}} & - \frac{2}{\sqrt{3}}
\end{pmatrix}
$$
The principal minors are $D_1 = - \frac{2}{\sqrt{3}} < 0$ and $D_2 = \frac{4}{3} - \frac{16}{3} < 0$. So, at the point $(\frac{1}{\sqrt{3}},\frac{1}{\sqrt{3}})$, $f$ has an indefinite Hessian matrix, which implies a saddle point. 

\medskip

At $(-\frac{1}{\sqrt{3}},-\frac{1}{\sqrt{3}})$, the Hessian is given by
$$
\mathscr{H}f =
\begin{pmatrix}
 \frac{2}{\sqrt{3}} & \frac{4}{\sqrt{3}} \\
\frac{4}{\sqrt{3}} & \frac{2}{\sqrt{3}}
\end{pmatrix}
$$
The principal minors are given by $D_1 = \frac{2}{\sqrt{3}}$ and $D_2 = \frac{4}{3} - \frac{16}{3} < 0$. At $(-\frac{1}{\sqrt{3}},-\frac{1}{\sqrt{3}})$, $f$ has an indefinite Hessian matrix, so that $f$ again has a saddle point.
\end{itemize}

\bigskip

\item {\it Find and classify the critical points of the function $f(x,y) = e^{-y} (x^2 - y^2)$.}


\medskip

We solve this in two steps. 

\medskip

\begin{itemize}
\item The first order partials are 
$f_x (x,y) = 2x e^{-y}$ and $f_y (x,y) = -e^{-y}(x^2 - y^2) - 2y e^{-y}$.
To determine the critical points of $f$, we set $f_x = f_y = 0$.  This gives,
\begin{eqnarray*}
f_x = 0 \Rightarrow x = 0 & \Rightarrow & f_y (0,y) = e^{-y} (y^2 - 2y) \\
f_y = 0 \Rightarrow y^2 - 2y = 0 & \Rightarrow & y(y - 2) = 0.
\end{eqnarray*}
Hence,  we see that our critical points occur at $(0,0)$ and $(0,2)$.

\smallskip

\item To classify the critical points, we calculate the Hessian matrix at each critical points. First, the second derivatives are given by
$$
f_{xx} (x,y) = 2 e^{-y} \quad f_{xy} (x,y) = f_{yx} (x,y) = 2x e^{-y}, 
$$
$$
f_{yy} (x,,y) = e^{-y} (x^2 - y^2 + 4y -2).
$$
At $(0,0)$ the Hessian matrix is given by
$$
\mathscr{H}f(0,0) =
\begin{pmatrix}
2 & 0 \\
0 & -2
\end{pmatrix}
\Rightarrow
D_1 = 2 > 0, \, D_2 = 4 < 0 \Rightarrow \textrm{indefinite, saddle point}.
$$
At $(0,2)$ the Hessian matrix is given by
$$
\mathscr{H}f(0,2) =
\begin{pmatrix}
2 e^{-2} & 0 \\
0 & 2 e^{-2}
\end{pmatrix}
\Rightarrow
D_1 = 2 e^{-2} > 0, D_2 = 4 e^{-4} > 0, 
$$
so that the Hessian matrix is positive definite and $f$ has a local minimum. 

(Alternatively, since the Hessian for both points is diagonal, we could just read the
classification of the critical points from the signs of the eigenvalues as in the lecture notes--without evaluating determinants. 
At $(0,0)$, one eigenvalue is positive and one is negative, so we have a saddle point. At
$(0,2)$, both eigenvalues are positive, so this is a local minimum.)


\medskip


\end{itemize}
The conclusion is that $f$ has a saddle point at $(0,0)$ and a minimum at $(0,2)$.


\end{enumerate}


\section*{Practice Problems}
\begin{enumerate}[1.]

\item {Let $\displaystyle f(x,y)=\frac{y}{x} + \frac{1}{y} +x$.

\medskip

(a)
This function has exactly one critical point. Find it.}

\medskip

{(b)
Find the second order Taylor polynomial of $f(x,y)$ at the critical point found in (a).}

\medskip

{(c) Does $f(x,y)$ have a minimum, maximum, or a saddle point at this critical point?}

\bigskip

\item {Let $\displaystyle f(x,y)=x^3 + 3 x^2y -y -y^3$. Find all critical points of $f$ and classify them as local minima,
maxima, or saddle points.}

\bigskip

\item {Let $\displaystyle f(x,y)=x^4-4xy+y^2$. Find all critical points of $f$ and classify them as local minima,
maxima, or saddle points.}

\bigskip


\item {Let $\displaystyle f(x,y)=x^3-3x^2y+xy-y^2$. Do there exist constants $A,B$ such that the function 
$g(x,y)=f(x,y)-Ax-By$ has a local minimum or maximum at $(1,2)$? If so, find all such $A$ and $B$.
If no, explain why.}

\bigskip

\item Let $f(x,y,z) = x^2 -2x + 2 y^2 + 3 z^2$. 

\smallskip

(a) This function has one critical point.  Find it and classify it.

\smallskip

(b) Why can we conclude that the critical point from part (a) is, in fact, a \underline{global} minimum?


\bigskip


\item  Let $f(x,y,z) = x^2 y^2 \sin (z)$.

\smallskip

(a) Determine all critical points of the function $f(x,y,z)$. 

\smallskip

(b) Calculate the Hessian matrix $\mathscr{H} (x,y,z)$ for an arbitrary point $(x,y,z)$.  

\smallskip

(c) Based on your answers to (a) and (b), explain why the second-order
test must necessarily fail at all critical points of this function.  

\bigskip



\item {
Let $f(x,y)$ be a function defined for all $(x,y)\in\rr^2$. Assume that $f$ and all its partial derivatives of all orders are continuous everywhere in the plane. Assume also that the second order Taylor polynomial of $f$ at $(a,b)=(0,0)$ is
$$
p_2(x,y)=2x^2+3y^2,
$$
and that the error $f(x,y)-p_2(x,y)$ satisfies
$$
\lim_{(x,y)\to (0,0)} \frac{f(x,y)-p_2(x,y)}{x^2+y^2}=0.
$$
Prove that $f$ has a local minimum at $(0,0)$. }

\bigskip






\item 
Let $f(x,y)$ be a function defined for all $(x,y)\in\rr^2$. Assume that $f$ and all its partial derivatives of all orders are continuous everywhere in the plane. Assume also that 
$$
f(x,y)=x^4-2y^4+g(x,y),
$$
where the function $g(x,y)$ satisfies $g(0,0)=0$ and 
$$
\lim_{(x,y)\to (0,0)} \frac{g(x,y)}{x^4+y^4}=0.
$$
Prove that $f$ does not have a local minimum or maximum at $(0,0)$. 







\end{enumerate}




