\section{Graphs and Surfaces}
We work with \textbf{functions} of $n$ real variables. Recall: a function $f = f(x_1,...,x_n)$ is a rule which assigns to each $(x_1,...,x_n)$ in the domain of $f$ (a subset of $\mathbb{R}^n$ -- see below) a unique real number $f(x_1,...,x_n)$.  We will use the following definitions and notations extensively.

\begin{itemize}
\item The \textbf{domain} $\mathcal{D}(f)$ is a subset of $\rr^n$; if not specified explicitly, we assume that $\mathcal{D}(f)$ is the largest set upon which $f$ is well defined.

\smallskip

\item The \textbf{range} $\mathcal{R}(f)$ is the set of all values attained by $f$,
$$
\mathcal{R}(f) = \{f(x_1,...,x_n) : \ (x_1,...,x_n) \in \mathcal{D}(f) \}.
$$
This is a set of real numbers. (Functions with values in other sets, for example complex-valued functions, can also be defined but will not be the subject of this course.)

\smallskip

\item The \textbf{graph} of $f$ is the set $\{(x_1,...,x_n, f(x_1,...,x_n)) :\  (x_1,...,x_n) \in \mathcal{D}(f) \}$. If the domain $\mathcal{D}(f) \subset \mathbb{R}^n$ (so that $f$ is a function of $n$ real variables) then the graph of $f$ is a subset of $\mathbb{R}^{n+1}$.
\end{itemize} 

\vfill
\pagebreak

Let us see some examples with computer-rendered images.

\begin{example}
The function $f(x,y) = \sqrt{4 - x^2 - y^2}$ is well defined so long as $4 - x^2 - y^2 \geq 0$.  So, we take the domain of $f$ to be $\mathcal{D}(f) = \{(x,y) \in \mathbb{R}^2 : x^2 + y^2 \leq 4 \}$. 


\begin{figure}[H]\label{21fig1}
\centering
\includegraphics[width= .5\textwidth]{21fig1.png}
\caption{The domain of $f(x,y) = \sqrt{4 - x^2 - y^2}$.}
\end{figure}

\bigskip

The range of $f$ is given by $\mathcal{R}(f) : = [0,2]$ and the graph of $f$ is given by $\{(x,y,z) \in \mathbb{R}^3: z = \sqrt{4 - x^2 - y^2} \}$--a \textit{half-sphere} in $\mathbb{R}^3$ of radius $r = 2$.


\begin{figure}[H]\label{21fig2}
\centering
\includegraphics[width= .7\textwidth]{21fig2.png}
\caption{The graph of $f(x,y) = \sqrt{4 - x^2 - y^2}$ in $\mathbb{R}^3$.}
\end{figure}
\end{example}

\vfill
\pagebreak

\begin{example}
The function $f(x,y) = \frac{1}{x^2 + y^2}$ is well defined whenever $(x,y) \neq (0,0)$, so that the domain $\mathcal{D}(f) = \{(x,y) \in \mathbb{R}^2 : (x,y) \neq (0,0) \}$. The range is given by $\mathcal{R}(f) = (0, \infty)$; to see this,  take $(x,y)$ close to $(0,0)$ and see what happens.



\begin{figure}[H]\label{21fig3}
\centering
\includegraphics[width= .9\textwidth]{21fig3.png}
\caption{The graph of $f(x,y) = \frac{1}{x^2 + y^2}$. This surface looks like the graph of $g(x) = \frac{1}{x^2}$ rotated about the $z$-axis.}
\end{figure}
\end{example}

\subsection{Visualizing 3D graphs using level curves}
Let $f(x,y)$ be a function of two variables. Consider the equation $f(x,y) = c$, where $c$ is a real number. Often\footnote{Not always -- for example, if $f(x,y)=C$ is a constant function, then the set of $(x,y)$ such that $f(x,y)=c$ is all of $\rr^2$ if $c=C$, and empty otherwise. In situations like that, it makes more sense to talk about {\it level sets} rather than {\it level curves}. Conditions that guarantee that the equation $f(x,y)=c$ defines a curve will be discussed later in connection with the Implicit Function Theorem.}, this equation defines a curve in $\mathbb{R}^2$.  These are the \textbf{level curves} of $f$. By drawing many such curves in $\mathbb{R}^2$, we can visualize the geometry of the graph of $f(x,y)$ (a surface in $\mathbb{R}^3$). This idea is similar to a contour map.

\begin{example}
The function $f(x,y) = \frac{1}{x^2 + y^2}$ has level curves given by the equations $\frac{1}{x^2+y^2} = c$. These are the circles $x^2 + y^2 = \frac{1}{c}$. The curves are coded so that the dark black level curve represents $f(x,y) = 1$.
The dashed red represents $f(x,y) = C >1$ and the solid light purple 
represents $f(x,y) <1$. All values of $C$ are evenly spaced (the common
difference is .2)



\begin{figure}[H]\label{21fig4B}
\centering
\includegraphics[width= .5\textwidth]{21fig4B.png}
\caption{Some of the level curves of $f(x,y) = \frac{1}{x^2 + y^2}$.}
\end{figure}


\end{example}

\begin{example}
The level curves of the function $f(x,y) = \sqrt{4 - x^2 - y^2}$ are given by $\sqrt{4 - x^2 - y^2}=C$, or $x^2+y^2=4-C^2$. For  $0\leq C<2$, these are circles as in the previous example, but the spacing is different.



\begin{figure}[H]\label{21fig4A}
\centering
\includegraphics[width= .5\textwidth]{21fig4A.png}
\caption{Some of the level curves of $f(x,y) =\sqrt{4 - x^2 - y^2}$.}
\end{figure}


\end{example}

\begin{example}
The graph of the function $f(x,y) = y^2 - x^2$ is a hyperbolic paraboloid.  The level curves $y^2 - x^2 = c$ are hyperbolas in the $xy$-plane, so long as $c \neq 0$.  However, if $c = 0$, then $y^2 - x^2 = 0$ so $y = \pm x$.  This gives a pair of lines intersecting the origin with slopes $\pm 1$.


\begin{figure}[H]\label{21fig5}
\centering
\includegraphics[width= .5\textwidth]{21fig5-2.png}
\caption{The hyperbolic paraboloid $z = y^2 - x^2$ along with cross-sections with planes $z = c$ for varying values of $c$. }
\end{figure}


\begin{figure}[H]\label{21fig5-3}
\centering
\includegraphics[width= .5\textwidth]{21fig5-3.png}
\caption{The level curves $y^2 - x^2 = c$.  The dotted vs. solid lines carry no mathematical meaning--rather, they are to assist any readers who may not  distinguish the colours!}
\end{figure}
\end{example}

\subsection{Level surfaces for functions of $3$ variables}
For a function $f(x,y,z)$ of three variables, the graph
$$
\{(x,y,z,f(x,y,z)) : (x,y,z) \in \mathcal{D}(f) \}
$$
is a hypersurface in four dimensional space (that is, $\mathbb{R}^4$).  Mathematically, this object is entirely well-defined! However, it is not possible to correctly visualize---much less draw---these hypersurfaces.

Despite this obstruction---that is, the confines of three dimensional awareness---we can still draw \textbf{level surfaces}.  These are the surfaces defined by the equations $f(x,y,z) = c$ for representative choices of $c$ in $\mathbb{R}$. Generically, for each value of $c$, this equation produces a surface in $\mathbb{R}^3$.

\begin{example}
The function $f(x,y,z) = z^2 - x^2 - y^2$ has level surfaces given by the equations $z^2 - x^2 - y^2 = c$.  When $c = 0$, this equation produces the cone $z^2 = x^2 + y^2$. When $c \neq 0$, we obtain hyperboloids (of one sheet when $c < 0$ and of two sheets when $c > 0$). The student is encouraged to review the definitions, equations and pictures for these surfaces from Section 1.5.



\begin{figure}[H]\label{21fig7}
\centering
\includegraphics[width= .7\textwidth]{21fig6.png}
\caption{The level surfaces of $f(x,y,z) = z^2 - x^2 - y^2$.}
\end{figure}
\end{example}

\subsection{Two final examples}
We introduce two examples where the level curves display a ``pathological'' behaviour. 

\begin{example}
Find the level curves of the function $f(x,y) = \frac{x^2 - y^2}{x^2 + y^2}$, defined when $(x,y) \neq (0,0)$.  
\end{example}

We compute its level curves as follows: suppose that $f(x,y)=c$, then 
$$
\frac{x^2 - y^2}{x^2 + y^2}=c, \hbox{ so that }x^2 - y^2=c(x^2 + y^2),
$$
$$
(1-c) x^2=(1+c)y^2.
$$
When $c\neq -1$, we can solve for $y^2$ and therefore $y$:
$$
y^2=\frac{1-c}{1+c}x^2,\ \ y=\pm \sqrt{ \frac{1-c}{1+c} } x.
$$
Notice that solutions only exist when $\frac{1-c}{1+c}\geq 0$, so that $-1<c\leq 1$. For each $c\in(-1,1)$, the above equation defines four half-lines meeting at (but not including) the point $(0,0)$. When $c=1$, we get $y=0$ so there are only two half-lines. Since we assumed that $c\neq -1$, we now consider that case separately:
$$
(1+1)x^2=0,\ \ x^2=0,\ \ x=0,
$$
which defines the $y$-axis with the $(0,0)$ point removed (again, two half-lines). 

Another way to solve for the level curves, in this question, is to change variables $x = r \cos \theta$ and $y = r \sin \theta$ for $r > 0$ and $\theta \in [0, 2 \pi)$.  This is known as the \textbf{polar coordinates} (you may know them from single-variable calculus). Using this,
$$
f(x,y) = f(r,\theta) = \frac{r^2 \cos^2 \theta - r^2 \sin^2 \theta}{r^2}= \cos^2 \theta - \sin^2 \theta = \cos (2 \theta).
$$
Notice that, since $f(r, \theta) = \cos (2 \theta)$, the range of $f$ is $[-1,1]$ (the same as the cosine function). For $c\in[-1,1]$, the level curves $f(x,y) = c$ are defined by the equation
$$
\cos (2 \theta) = c
$$
which, again, describes half-lines meeting at the origin. 

All these half-lines corresponding to different values of $c$ meet at the point $(0,0)$. At the point $(0,0)$ itself, the function is not defined (because we can't divide by 0). If we try to fill in the gap at $(0,0)$ by using the values of $f$ from nearby, it turns out that we cannot do that because $f(0,0)$ would have multiple values! We will be able to say all this in a more rigorous way after we introduce limits and continuity.




%\vfill



\begin{figure}[H]\label{21fig6}
\centering
\includegraphics[width= .7\textwidth]{21fig7.png}
\caption{Some level curves of the function $f(x,y) = \frac{x^2 - y^2}{x^2 + y^2}$}
\end{figure}



\begin{example}
Find the level curves of the function $f(x,y) = \frac{x^4 - y^2}{x^4 + y^2}$, defined for $(x,y) \neq (0,0)$.  
\end{example}

The level curves are given by the equation
$$
 \frac{x^4 - y^2}{x^4 + y^2} = c \Leftrightarrow x^4 - y^2 = c(x^4 + y^2) \Leftrightarrow y = \pm \sqrt{\frac{1 - c}{1 + c}} \, x^2,
$$
so long as $-1 <  c \leq 1$. This restriction on $c$ guarantees that $\frac{1 -c}{1 + c} \geq 0$. 
When $c = -1$, we instead obtain the equation $2 x^4 = 0$, which describes the vertical line $x = 0$.
To summarize:
\begin{itemize}
\item When $-1 < c < 1$,  we get the two parabolas $y = \pm \sqrt{\frac{1 - c}{1 + c}} \, x^2$ with the origin $(0,0)$ removed.

\item When $c = - 1$, we obtain the vertical line $x = 0$ with the origin removed.

\item When $c = 1$, we obtain the horizontal line $y = 0$ with the origin removed.
\end{itemize}

Notice that, in all three situations, the level curves do not contain the origin $(0,0)$. This is again because the domain of $f(x,y) = \frac{x^4 - y^2}{x^4 + y^2}$ never contained the origin! In this example, just like in the previous one, many level curves corresponding to different values of $f$ converge to one point. Here, however, those curves are parabolas and not lines.


\begin{figure}[H]\label{21fig8}
\centering
\includegraphics[width= .7\textwidth]{21fig8.png}
\caption{Some level curves of the function $f(x,y) = \frac{x^4 - y^2}{x^4 + y^2}$.}
\end{figure}


\section*{Practice Problems}
\begin{enumerate}[1.]
\item
{ 
Let $f(x,y)=\sqrt{y-x^2}$.
Find the domain of $f$, and find the equations of its level curves.}

\medskip


\item {Find the function $f(x,y,z)$ if for each constant $D$ the level surface $f(x,y,z)=D$ is the plane perpendicular to $\mathbf{n}= -3 \ii + \jj + 2\kk$ and passing through the point $(0,0,D^5 )$.}


\end{enumerate}




