\section{Global Extrema on Restricted Domains}
We define a class of domains that will be important in this section.


\begin{definition}
A domain $X \subset \mathbb{R}^n$ is \textbf{compact} if it is bounded and closed.
\end{definition}

\smallskip

For some examples, the closed ball in $\mathbb{R}^3$ and a rectangle together with its boundary in $\mathbb{R}^2$ are both compact. The following theorem, given here without proof, says that a function $f$ continuous on a compact set $X$ attains its global extrema on that set.

\begin{theorem}
If $X \subset \mathbb{R}^n$ is compact and $f : X \rightarrow \mathbb{R}$ is continuous, then $f$ attains its global minimum and maximum values on $X$.  That is, there are points $\mathbf{a}_{min} \in X$ and $\mathbf{a}_{max} \in X$ such that
$
f(\mathbf{a}_{min}) \leq f (\mathbf{a}) \leq f(\mathbf{a}_{max})$
for all $\mathbf{a} \in X.$
\end{theorem}

\medskip

Note that, if $f$ has a \underline{global} minimum at $\mathbf{a}_{min}$ then it must also have a \underline{local} minimum at $\mathbf{a}_{min}$. Therefore, the point $\mathbf{a}_{min} \in X$ has to be one of the following:
\begin{itemize}
\item a boundary point of $X$;
\item a singular point of $f$ (so that $\nabla f$ does not exist at $\mathbf{a}_{min}$); or,
\item a critical point of $f$ (so that $\nabla f (\mathbf{a}_{min}) = 0$).
\end{itemize}
Of course, a similar statement holds for $\mathbf{a}_{max}$. Therefore, the procedure to minimize or maximize $f$ on a compact domain $X$ is as follows.

\begin{center}
\fbox{
\begin{minipage}{\textwidth}
\begin{center}
\textbf{Maximizing/Minimizing Continuous Functions on Compact Sets}
\end{center}


\begin{enumerate}[(1)]
\item Find all critical and singular points $\mathbf{a}_1,...,\mathbf{a}_k \in X$ of the function $f$. Then, compute the values $f(\mathbf{a}_1),...,f(\mathbf{a}_k)$.

\medskip

\item Determine the minimum or maximum values of $f$ on the boundary of $X$ and note the points $\mathbf{a}_{-}$ and $\mathbf{a}_{+}$ where $f$ attains these minimum/maximum values \textrm{on the boundary}. 

\medskip

\item Compare all values $f(\mathbf{a}_1),..., f(\mathbf{a}_k)$ from Step $(1)$ with the values $f (\mathbf{a}_{-})$ and $f(\mathbf{a}_{+})$ determined in Step $(2)$.   Then, from this list, choose $\mathbf{a}_{min}$ and $\mathbf{a}_{max}$ by determining where $f$ is minimized or maximized (respectively).
\end{enumerate}
\end{minipage}
}
\end{center}

\medskip
Examples of using this procedure are given in the Worked Problems below.
We note some additional considerations:

\begin{itemize}

\item
If our domain $X \subset \mathbb{R}^n$ is \underline{not compact},  we may still be able to find a global minimum or maximum of $f$ on $X$. However, we must also consider what happens as our input $\mathbf{x}=(x_1,...,x_n)$ approaches infinity (that is, when one or more of the variables $x_j$ satisfy $|x_j| \rightarrow \infty$) if $X$ is not bounded, and/or as $\mathbf{x}$ approaches the boundary of $X$ if $X$ is not closed. A concrete example is considered in the Worked Problems below.

\medskip

\item \underline{We do not recommend using the second derivative test in (1)}
if your goal is only to find the largest and smallest values of $f$ on a domain (and not to classify its critical points). While the second derivative test allowed us to determine whether the function had a \underline{local} extremum at a critical point, it is entirely possible for a function $f : X \rightarrow \mathbb{R}$ to have local extrema without ever attaining a global minimum or maximum.  Take, as an example,  the contour plot of the function $f(x,y)$ in Figure 4.4.


\medskip

You could use the second derivative test to eliminate some of the critical points (if $f$ has a saddle point at a point $\mathbf{a}$ in the interior of $X$, then it does not have a minimum or maximum there), but it is easier to just evaluate $f$ at those points.

\medskip

\item \underline{Min/max on the boundary:} in the Worked Problems and Practice Problems below, we can determine the minimum and maximum values on the boundary
of $X$ using single-variable calculus. In general, especially for higher dimensional sets $X \subset \mathbb{R}^n$ with $n>2$, we may need more tools. There is a separate procedure for this (the method of \textit{Lagrange multipliers}) that we will cover in the next section.


\end{itemize}


\begin{figure}[H]\label{42fig5}
\centering
\includegraphics[width=.9\textwidth]{42fig5.png}
\caption{The function $f(x,y)$ has a local maximum at the marked point. However, since $f$ grows as $x \rightarrow \infty$, we cannot conclude that $f$ has a global maximum anywhere. Note: different colors correspond to distinct values of $C$ in the equation $f(x,y) = C$. }
\end{figure}




\section*{Worked Problems}
\begin{enumerate}[1.]
\item {\it Find the largest and smallest values of the function $f(x,y) = x^2 - 2xy + 2y$ on the rectangle $0 \leq x \leq 3$, $0 \leq y \leq 2$. }


\begin{figure}[H]\label{42fig1}
\centering
\includegraphics[width= .4\textwidth]{42fig1.pdf}
\end{figure}


\medskip

We follow the procedure for determining a global maximum and minimum outlined previously.

\medskip

\begin{enumerate}
\item Let us first find the critical points of $f(x,y)$.  We know that $f_x (x,y) = 2x - 2y$ and $f_y (x,y) = -2x + 2$.  So, 
$$
f_x (x,y) = f_y (x,y) = 0 \Leftrightarrow 2x - 2y = 0, \, -2x + 2 = 0 \Leftrightarrow x = 1, y = 1.
$$ 
So, $f(x,y)$ has exactly one critical point interior to the rectangle: the point $(x,y) = (1,1)$.  Also, the function $f$ has no singular points; this follows because $f$ is $C^1$ everywhere, and in particular its first-order derivatives exist everywhere on the rectangle. 

\smallskip
At the one critical point $(x,y) = (1,1)$, we know that $f(1,1) = 1$.

\medskip

\item For the boundary of the rectangle, we split the boundary into four line segments as shown in the diagram above. We then find the minimum and maximum value of $f$ on each segment. We have:
\begin{align*}
\hbox{on } L_1 , &\  f(x,0) = x^2,  \  0 \leq x \leq 3  \Rightarrow \textrm{ min } f(0,0) = 0, \textrm{ max } f(3,0) = 9. \\[1ex]
\hbox{on } L_2 , &\  f(3,y) = 9 - 4y, \ 0 \leq y \leq 2 \Rightarrow \textrm{ min } f(3,2) = 1, \textrm{ max } f(3,0) = 9. \\[1ex]
\hbox{on }  L_3 , &\  f(x,2) = (x - 2)^2, \ 0 \leq x \leq 3 \Rightarrow \textrm{ min } f(2,2)  =0, \textrm{ max } f(0,2) = 4. \\[1ex]
\hbox{on } L_4 , &\  f(0,y) = 2y, \ 0 \leq y \leq 2 \Rightarrow \textrm{ min } f(0,0) = 0, \textrm{ max } f(0,2) = 4.
\end{align*}

\medskip

\item Comparing the largest and smallest values found in $(a)$ and $(b)$, we see that $f(3,0) = 9$ and $f(0,0) = f(2,2) = 0$ are the global (over the rectangle) maximum and minima (respectively) of the function $f(x,y)$.
\end{enumerate}


\bigskip




\item {\it We want to make a rectangular box without lid from $12 m^2$ of cardboard. Find the maximal volume of such a box. 
 \textbf{Note}: this worked problem gives an example where the domain of our function $V$ is \underline{unbounded}, hence not compact.}


\begin{figure}[H]\label{42fig2}
\centering
\includegraphics[width= .6\textwidth]{42fig2.pdf}
\end{figure}


\medskip

We seek to maximize the volume of the box, which is given by the formula $V(x,y,z) = xyz$ for $x,y,z > 0$.  Using that we have $12 m^2$ of cardboard (an initial constraint),  we may write $z = z(x,y)$ as a function of the length $x$ and width $y$.  This follows since
$$
\textrm{Surface Area } = 2 x z + 2 y z + x y = 12 \Rightarrow z (x,y) = \frac{12 - xy}{2 (x + y)}.
$$
Hence, we seek to maximize the volume function
$$
V(x,y) = x y z(x,y) =xy \bigg(\frac{12 - xy}{2 (x + y)} \bigg) = \frac{12 xy - x^2 y^2}{2 (x + y)}
$$
We have $x\geq 0$ and $y\geq 0$ (the dimension of a box cannot be negative), and $xy\leq 12$ (the area $xy$ of the bottom of the box is bounded by the total area of available cardboard). Note that the above formula for $V(x,y)$ is undefined when $(x,y)=(0,0)$ (since then $x+y=0$). However, as $(x,y)\to (0,0)$, we have
$$
V(x,y)= \frac{12 xy - x^2 y^2}{2 (x + y)}\leq \frac{12 xy - x^2 y^2}{2 x}\leq 12 y - x y^2\to 0,
$$
so that we can define $V(0,0):=0$. With that addition, $V(x,y)$ is a continuous function of $(x,y)$ on the domain
$$
X=\{(x,y)\in\RR^2:\ x\geq 0,\ y\geq 0,\ xy\leq 12\}
$$
bounded by the lines $x = 0$, $y = 0$ and the hyperbola $xy = 12$. This is \underline{not} a compact set.



\begin{figure}[H]\label{42fig3}
\centering
\includegraphics[width= .6\textwidth]{42fig3}
\caption{The domain of $V(x,y)$ is an unbounded set--hence, non-compact.}
\end{figure}

However, in this example, we can still find the global maximum of $V(x,y)$. Common sense says that the largest volume will be attained when the box is ``reasonably'' sized, so that very long and narrow boxes should not maximize the volume. To make this argument rigorous, we will prove that the function $V(x,y)$ is small at the tail ends of the domain, so that we can discard these tail ends and maximize $V$ on a smaller compact domain instead. We implement this in the steps (a)-(c) below.

\medskip

\begin{enumerate}
\item We first determine the critical points of $V(x,y)$.  We have:
\begin{eqnarray*}
\frac{\partial V}{\partial x} & = & \frac{(12y - 2 x y^2)(x+y) - (12xy - x^2 y^2)}{2 (x + y)^2} \\
\quad & = & \frac{1}{2 (x + y)^2} \big[12 y^2 - x^2 y^2 - 2xy^3 \big]
\end{eqnarray*}
Since $V(x,y) = V(y,x)$--meaning that $V$ is symmetric under the change of variables $x \mapsto y$--we get
$$
\frac{\partial V}{\partial y} = \frac{1}{2 (x+y)^2} \big[ 12 x^2 - x^2 y^2 - 2x^3 y\big]
$$
by interchanging the variables. To determine the critical points of $V$, we solve
\begin{eqnarray*}
\frac{\partial V}{\partial x} = \frac{\partial V}{\partial y} = 0 & \Rightarrow & 12 y^2 - x^2y^2 - 2xy^3 = 12 x^2 - x^2 y^2 - 2x^3 y = 0 
\\[1ex]
\quad & \Rightarrow & y^2(12 - x^2 - 2xy) = x^2(12 - y^2 - 2xy) = 0.
\end{eqnarray*}
If $x=0$ or $y=0$, we are on the boundary of $X$; we defer these cases to the next part of the procedure. If $x\neq 0$ and $y\neq 0$, we get
$$ 
12 - x^2 - 2xy = 0 \textrm{ and } 12 - y^2 - 2xy = 0.
$$
Subtracting the above equations, we have
$$
y^2 - x^2 = 0 \Rightarrow x^2 = y^2 \Rightarrow x = y,
$$
since both $x$ and $y$ are positive.  Now, back-substitution gives
$$
0 = 12 - x^2 - 2xy = 12 - x^2 - 2x^2 = 12 - 3x^2 \Rightarrow x = 2.
$$
Hence, our only critical point occurs at $(x,y) = (x,x) = (2,2)$.  At this point,
$$
V(2,2) = \frac{12 \cdot 4 - 4 \cdot 4}{2 \cdot 4} = 4.
$$

\medskip

\item We now consider the boundary of $X$.  When $(x,y) = (0,y)$ with $y\neq 0$ or $(x,y) = (x,0)$ with $x\neq 0$, we have $V(x,y) = x y z(x,y) = 0$. Moreover, if $xy = 12$, then
$$
V(x,y,z) = xy \frac{12 - xy}{2 (x+y)} = 0,
$$
so that $V(x,y,z)$ clearly does not attain its maximum value at any point of the boundary of $X$.

\medskip

\item We have one additional step, since the domain of $V(x,y)$ is unbounded.  Namely, we need to bound $V(x,y)$ for ``large enough'' values of $x$ and $y$.  To accomplish this, first notice that since $xy \leq 12$ on the domain of $V(x,y)$, we necessarily have
$$
V(x,y)  = \frac{12 xy - x^2 y^2}{2 (x + y)} \leq \frac{12 xy}{2 (x+y)} = \frac{6 xy}{x + y} \leq \frac{6 \cdot 12}{x + y} = \frac{72}{x + y}
$$
Since $x > 0$ and $y > 0$, we know that if either $x \geq 72$ or $y \geq 72$, then
$$
V(x,y) = \frac{72}{x + y} \leq \frac{72}{\max \{x, y\}} \leq \frac{72}{72} = 1.
$$
Importantly, we have $1 \leq V(2,2) = 4$! So,  in the portion of the domain where $x \geq  72$ or $y \geq 72$, $V$ cannot attain its global maximum.
\end{enumerate}


\begin{figure}[H]\label{42fig4}
\centering
\includegraphics[width= .6\textwidth]{42fig4}
\caption{The domain of $V(x,y)$ is unbounded. However,  whenever we are ``far enough'' away from the origin--so that either $x$ or $y$ is large--the function $V(x,y)$ is small.}
\end{figure}


We can now put the argument together as follows. We write our domain $X$ as $X=X_1\cup X_2\cup X_3$, where
\begin{align*}
X_1&= \{(x,y)\in X:\ x\leq 72,\ y\leq 72\},
\\
X_2&= \{(x,y)\in X:\ x\geq 72\},
\\
X_3&= \{(x,y)\in X:\ y\geq 72\}.
\end{align*}
The domain $X_1$ \underline{is} compact, so we can apply the procedure for compact sets here. We found a critical point $(2,2)$ with $V(2,2)=4$; we checked in (b) that on the parts of the boundary of $X_1$ where $x=0$, $y=0$, or $xy=12$, we have $V(x,y)=0$; and in (c), we checked that on the parts of the boundary where $x=72$ or $y=72$, we have $V(x,y)\leq 1$. Therefore the global maximum \underline{on $X_1$} is $V(2,2) = 4$. But we also checked in (c) that $V(x,y)\leq 1$ on $X_2\cup X_3$, so that adding $X_2$ and $X_3$ to the domain does not change the outcome.


We conclude that $V(2,2) = 4$ is the global maximum, and choose a box of dimensions $(x,y,z) = (2,2,1)$ to maximize the volume.

\medskip
\noindent
{\bf Additional notes on the above argument:} 

\medskip

\begin{itemize}
\item We needed to split $X$ into $X_1$, $X_2$, and $X_3$ so that the largest value of $V$ on $X_2\cup X_3$ would be less than the largest value on $X_1$. That's why we did Step (a) first, and then chose the decomposition of $X$ \underline{after} we had a guaranteed value $V(2,2) = 4$ on what would become $X_1$. 

\smallskip

\item There is nothing particular about the number 72 as the cut-off for $x$ and $y$. We chose it because it was easy to use, but any other cut-off with the same property (that $V$ should be less than 4 on $X_2\cup X_3$) would also work. Also, we estimated $V(x,y)$ by $72(x+y)^{-1}$ at the beginning of part (c), but alternative solutions using different estimates might have also been possible.

\end{itemize}

\end{enumerate}


\section*{Practice Problems}
\begin{enumerate}[1.]
\item{Find the largest and smallest values of the function $f(x,y)=x^3-3xy+3y^2$ on the closed triangle with vertices
$(0,0), (1,0), (1,1)$.}

\medskip

\item{Find the largest and smallest values of the function $f(x,y)=4x-2xy+y^2$ on the square $\{(x,y):\ 0\leq x\leq 2,\ 0\leq y\leq 2\}$.}


\medskip

\item 
Find, with proof, the global minimum and maximum of the function $f(x,y)=\frac{xy}{x^4+y^4+32}$ defined
for all $x,y$, by following the steps listed below.

\smallskip

(a) Find all critical points of $f$, evaluate $f(x,y)$ at these points, and choose the largest and
smallest value, $M$ and $m$.

\smallskip


(b) Prove that $x^4+y^4 \geq \frac{1}{2}(x^2+y^2)^2$.


\smallskip

(c) Use (b) to prove that $|f(x,y)|\leq \frac{2}{x^2+y^2}$. Based on this, prove that
the values $M$ and $m$ from (a) are in fact the global minimum and maximum values.


\medskip


\item { Let $ f(x,y)=2x^2-7x-xy+y^2$. Find the global minimum of $f(x,y)$ on $\rr^2$,  by following the procedure below.

\medskip

(a) Find all critical points of $f$. Evaluate $f$ at these points.

\medskip

(b) Prove that if $|x|$ and $|y|$ are large enough, then $f(x,y)$ is greater than the values you found in (a). 
\medskip

(c) Conclude that the global minimum is attained at a point found in (a).}







\medskip



\item {Find the global minimum and maximum of $f(x,y)=(2x^2-y^2)e^{-x^2-y^2}$
on $\rr^2$, with proof.}

\medskip


\item Let $ f(x,y)=x^2y-2xy^2+3y$. Find the largest and smallest values of $f(x,y)$ on the following sets,
or else prove that they do not exist:

(a)  $D_1=\{(x,y):\ x\geq 0, 0\leq y\leq 2\}$, 

(b)  $D_2=\{(x,y):\ x\geq 0, y\geq 0, xy\leq 16\}$. 

Make sure that you account for both regions being unbounded. 




\end{enumerate}





