\documentclass{article}

\title{Maple Samples}
\author{Your Name Here}

\begin{document}

\maketitle

\abstract{This document gives some samples of how to use
Maple to compute the types of derivatives that come up
in Calculus III}

\section*{Graph the function}

Graph $z=f(x,y)$.  In this example, $z=\sqrt{9-x^2-y^2}$
\begin{verbatim}
f:=(x,y)->sqrt(9-x^2-y^2);
plot3d(f(x,y),x=-3..3,y=-3..3);
\end{verbatim}
Compare that with the following:
\begin{verbatim}
z:=sqrt(9-x^2-y^2);
plot3d(z,x=-3..3,y=-3..3);
\end{verbatim}
\subsection*{Try This:}  Plot $z=\sin(xy)$, for $x\in[-10,10]$ and $y\in [-10,10]$.
Change the color scheme to ``Z Hue'' by adding the option
\verb+shading=zhue+,  and increase the number
of points used to plot by adding \verb+grid=[80,80]+, and finally
remove the grid lines by adding the option
\verb+style=surface+


\section*{Plot the level curves}

Plot the level curves (also called contours) of the function
$z=f(x,y)$.  The Maple command is \verb+contourplot+
\begin{verbatim}
with(plots):
z:=(x+y)/(sin(y)+2);
contourplot(z,x=-3..3,y=-3..3);
\end{verbatim}
Now change the number of points used and see if the graph changes.
We can also tell Maple which contours to graph.  In this example,
we compare the plot of $f(x,y)=\sin^2(x)+\frac{1}{4}y^2$ with its
contours at $1/10,1/2,1,3$-  We'll visualize the results in 3-D.
\begin{verbatim}
g:=(sin(x))^2+(1/4)*y^2;
plot3d(g,x=-5..5,y=-2..2);
contourplot(g,x=-5..5,y=-2..2,contours=[1/10,1/2,1,3]);
contourplot3d(g,x=-5..5,y=-2..2);
\end{verbatim}


\section*{Multiple Limits.}

\subsection*{Examples:} Compute the limits (if they exist) in Maple:
$$ \lim_{(x,y)\rightarrow (0,0)}\frac{x^2-y^2}{x^2+y^2}\qquad
\lim_{(x,y)\rightarrow (0,0)}\frac{3x^2y}{x^2+y^2}$$
\begin{verbatim}
limit( (x^2-y^2)/(x^2+y^2), {x=0, y=0} );
limit( (3*x^2*y)/(x^2+y^2), {x=0,y=0} );
\end{verbatim}

Maple could not compute the second limit- Try graphing them to see
if the limit exists at the origin:
\begin{verbatim}
plot3d((x^2-y^2)/(x^2+y^2),x=-1..1,y=-1..1);
plot3d(3*x^2*y/(x^2+y^2),x=-1..1,y=-1..1);
\end{verbatim}
You should see that the limit does not exist in the first graph,
the limit is zero in the second (even though Maple could not compute it).


\section*{Partial Derivatives:}

{\it Before Going Any Further:}  If you've been following the examples
in a Maple worksheet, you might remove all the output (from the Edit
menu), save the worksheet and clear the variables before going further:
\begin{verbatim}
restart;
\end{verbatim}


\subsection*{Example:} If $f(x,y,z)=x{\rm e}^{xy}\ln(z)$.  Compute some
first and second partial derivatives:

\begin{verbatim}
f:=x*exp(x*y)*ln(z);
fx:=diff(f,x);
fxz:=diff(fx,z);
fxx:=diff(f,x$2);
fyz:=diff( diff(f,y),z);
\end{verbatim}
Notice the \verb+$2+ gives you the second derivative.

\subsection*{Example:}
Use the definition of the partial derivative to compute $f_x(x,y,z)$, if
$$
f(x,y,z)=\sqrt{x^2+y^2+z^2}
$$
\begin{verbatim}
f:=(x,y,z)->sqrt(x^2+y^2+z^2);
DiffQuot:=(f(x+h,y,z)-f(x,y,z))/h;
fx:=limit(DiffQuot,h=0);
\end{verbatim}

\subsection*{The Gradient}
Compute the Gradient, $\nabla f=[f_x,f_y,f_z]$

In Maple, if $f(x,y,z)=3x^2+2yz+5x-6y$, then the gradient is
computed as the following.  We will also find where the
gradient is zero, and check by substituting it back into
the gradient, and for fun, substitute it into the function:
\begin{verbatim}
with(linalg):
f:=3*x^2+2*y*z-5*x+6*y;
df:=grad(f, vector([x,y,z]));
S:=solve({df[1]=0,df[2]=0,df[3]=0});
subs(S,[df[1],df[2],df[3]]);
subs(S,f);
\end{verbatim}

\subsection*{Contours and Gradients}
Plot the contours of $f(x,y)=x^2-y^2$, together with
some gradient vectors.
\begin{verbatim}
with(plots):
A:=contourplot(x^2-y^2,x=-4..4,y=-4..4):
B:=gradplot(x^2-y^2,x=-4..4,y=-4..4,grid=[6,6],arrows='slim'):
display({A,B});
\end{verbatim}

\section*{Example In Depth:}

The length of a diagonal of a box is to be 1 meter.  Find the maximum
possible volume.

Solution:  Let $x, y$ be the dimensions of the base of the box, and $z$
be its height.  We want to find the maximum of $V=xyz$, where there is a
restriction on the diagonal- Its length is 1:
$$
V=xyz \qquad \mbox{ where }\sqrt{x^2+y^2+z^2}=1
$$
Solving the restriction for $z$ gives a function of two variables-  Find
the maximum of
$$
V=xy\sqrt{1-x^2-y^2} \quad \mbox{ where }x^2+y^2\leq 1
$$
The minimum and the maximum of $V$ occurs at either its critical
points or along the boundary, so we check both:
\begin{verbatim}
with(linalg):
V:=x*y*sqrt(1-x^2-y^2);
dV:=grad(V,vector([x,y]));
H1:=[solve({dV[1]=0,dV[2]=0})];
H2:=[allvalues(H1[2])];
H3:=subs(H2[1],V);
\end{verbatim}
Now, $V=0$ along the circle $x^2+y^2=1$, and along $x=0$ or $y=0$.
Therefore, the maximum value is in \verb+H3+, and it occurs at the critical point
in \verb+H2[1]+ (which was $x=y=1/\sqrt{3}$)
\end{document}

