% maple lab1 S2017
\documentclass[leqno]{article}
\input{linalg.sty}
\def\MAPLE{{\tt Maple}}
\def\rf#1{(\ref{#1})}
\def\Prob#1#2{\par\bigskip\par\noindent
{\large\sf Problem #1}. {\bf #2}\par}
\parskip=3pt
\def\MAPLE{{\tt maple}}
% \begin{topics}{template} ... \end{topics}
% used like enumerate, itemize, description environments
% The item[] is never optional!
%
%\newcommand{\topicslabel}[1]{\mbox{#1}\hfil}
%\newenvironment{topics}[1]{
%    \begin{list}{}{%
%      \let\makelabel\topicslabel
%      \settowidth{\labelwidth}{\topicslabel{#1}}
%      \setlength{\leftmargin}{\labelwidth}
%      \advance\leftmargin by 1.5em}
%}{\end{list}}
\pagestyle{plain}
\setlength{\textheight}{9.8in}
\begin{document}
\thispagestyle{empty}
 {\bf Name~}\underline{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}\hfill
% {Class Time~}\underline{~~~~~~~~}\newline


\begin{center}
\bf Math 2280 Maple Project 1 \\
{\small\bf Spring 2017}
\end{center}


%{\bf Due date}: See the internet due dates. Maple Project 1 has four
%problems L1.1, L1.2, L1.3, L1.4.

{\bf Submitted work}. Please submit one stapled package. Some handwritten work is expected, which should display the steps shown
in examples below. Maple code is expected to parallel the code
given in the examples below. The final pages are expected to be appendices made by printing
one or more maple work sheets.


{\bf Tutorials}. Students without maple exposure should schedule a private tutorial in JWB 113.  Others may start their own tutorial by attempting this project unaided
with help from the Utah maple online tutorial\newline
{\tt http://www.math.utah.edu/~gustafso/s2017/maple-web-help/}.

{\bf References}: %Edwards-Penney, pages 55--57.
Code in \MAPLE{} appears in \verb|2280mapleL1-intro-S2017.txt| at URL
\verb|http://www.math.utah.edu/~gustafso/|. This document:
\verb|2280mapleL1-intro-S2017.pdf|.

\smallskip

\Prob{L1.1}{(Quadratic equation)} Solve the quadratic equation
$ax^2+bx+c=0$ and display its factorization:
\newline
 (L1.1A) $a=8$, $b=22$, $c=15$;
\newline
 (L1.1B) $a=1$, $b=2$, $c=6$;
\newline
 (L1.1C) $a=2$, $b=16$, $c=32$.
\newline
In your solution, show the {\bf solution steps by hand} and also
the \MAPLE{} code which checks the answer. Details should parallel
those of Example 1, below.

\Prob{L1.2}{(Functions and plotting)} Define the following
functions and plot domains, then plot them.
\newline (L1.2A) $e^{-x}\sin(5\pi x)$, $0\le x \le 1$.
\newline (L1.2B) $|4\ln(5+x)-1|$,$-2\le x \le 4$.
\newline (L1.2C) Let $a=5$, $b=8$, $c=\pi/12$, $t_0=15$. Plot
 $a+b\cos(c(t-t_0))$, $0\le t \le 48$.
\newline (L1.2D) $\sinh(2\sin(\theta)+3\cos(\theta))$, $-\pi \le \theta \le
\pi$.
\newline
In the four solutions, show only the maple code and the graphics.
Please shrink the graphics to about 1/4 page, before printing.
See Example 2 below.
% a:=6; b:=5; c:=Pi/12; t0:=15; g:=unapply(a+b*cos(c*(t-t0)),t);
% plot(g(t),t=0..72);
\medskip

\Prob{L1.3}{(Derivatives)} Compute the indicated derivative(s) by
hand and then check your answer in maple.
 \newline (L1.3A) $\dd\frac{dy}{dx}$,
 $y=\dd\frac{(x-1)^2}{x^3+1}+xe^{-2x}\cos(3x)$\\[1ex]
 \newline  (L1.3B) $\dd\partial_x z$, $\partial_y z$, $z= \dd\cosh (x)\sinh
(x+y)$\\[1ex]
 \newline  (L1.3C) $\dd\partial_{c_1} u$, $\dd\partial_{c_2} u$,
$\dd\partial_{c_3}
u$, $\dd
 u=c_1x^2+c_2+c_3xe^{2x}$\\[1ex]
 \newline  (L1.3D) $\dd\partial_x\partial_y w$, $\dd w=e^{xy}\tan(x^2+y^2+1)$


\Prob{L1.4}{(Vector Partials and Jacobian)}

 (L1.4A) Compute the vector partials $\partial_{t_1}\.u$ and
$\partial_{t_2}\.u$,
for
$$\.u = (1+2t_1-t_2)\vec{\imath}
+(2-t_1+3t_2)\vec{\jmath}+(2t_1+5t_2)\vec{z}.$$

 (L1.4B) Compute the Jacobian matrix and determinant at $x=y=0$ for
vector function $z_1\vec{\imath}+z_2\vec{\jmath}$, given
$$\dd z_1 =
x(x+2y-1), \quad z_2=y(-x+3y+2).$$
 Do a hand computation on paper and then check your answer in maple.
\vfill

{ {\sf Staple this page
on top of the maple work sheets.} {\bf Start the hand solution on a separate page.} \newline
\medskip
Examples on the next page \ldots}
\newpage


{\bf Example 1}. {\large\sf Solve $2x^2+8x+12=0$ by hand and check
using \MAPLE{}}.

{\bf Solution}: Divide by 2. Then square-completion $(x+2)^2+2=0$
gives
conjugate roots $x=-2+\sqrt2i$, $x=-2-\sqrt2i$. By the root-factor
theorem of college algebra, the quadratic equation has factors
$(x-\mbox{root 1})$ and $(x-\mbox{root 2})$. Then the
factorization
is $2(x+2-\sqrt2i)(x+2+\sqrt2i)=0$, because FOIL expansion gives leading
term $2x^2$.

The roots may also be found
from the quadratic formula, in which case the root and factor
theorems of algebra apply to translate each root $x=r$ into a
factor $x-r$ of the quadratic equation.

The maple check reproduces the original quadratic equation
from its factors and leading coefficient. The \MAPLE{} code is
\begin{verbatim}
 eq:=2*x^2+8*x+12:
 ans:=[solve(eq=0,x)];
 eq1:=2*(x-ans[1])*(x-ans[2])=0;
 expand(eq1);
\end{verbatim}
Notation: Square brackets delimit an array, e.g., \fbox{\tt
F:=[-1,3,5];} defines array {\tt F} with three elements $-1$, $3$,
$5$. Symbol \fbox{{\tt F[1]}} extracts the first element from
array {\tt F}, while \fbox{\tt F[2]} extracts the second element.


\bigskip

{\bf Example 2}.  {\large\sf Define a function $y=x^2+5x+6$ on $-4
\le x \le -1$ using \MAPLE{} and plot it}.

{\bf Solution}: The \MAPLE{} code which applies is
\begin{verbatim}
 f:=unapply(x^2+5*x+6,x): a:=-4: b:=-1:
 plot(f(x),x=a..b);
\end{verbatim}
The construct \fbox{\tt f:=unapply(x$\hat{~}$2+5*x+6,x)} is an
inline function definition. Subsequent use of the symbol {\tt f}
requires two parentheses and a function argument, e.g., {\tt
f(x)}, {\tt f(-1.1)} are valid.

The inline function definition \fbox{\tt
f:=x->x$\hat{~}$2+5*x+6} uses a minus sign \fbox{\tt -} and a greater
than sign \fbox{\tt >} to separate the variable name \fbox{\tt x} from the
function definition \fbox{\tt x$\hat{~}$2+5*x+6}. This alternative
construction may appear in later maple code. In this elementary
example, there is no difference between the two constructs. The
maple function \fbox{\tt unapply} is more robust and produces
fewer surprises for novice maple users.

{\bf Constants and Empty Plots}.  The constant $\pi$ is coded in \MAPLE{} as \fbox{\tt Pi}, the upper and lowercase letters being significant. Coding \fbox{\tt
c=Pi;} prints an equation. Coding \fbox{\tt c:=Pi;} assigns $\pi$ to symbol {\tt c}.
The error message {\bf
empty plot} can mean that a symbol is undefined. For example,
\fbox{\tt plot(x+PI,x=0..1);} will not plot. To see why, use \fbox{\tt
p:=plot(x+PI,x=0..1);} to display the plot data. The offending undefined
symbol is {\tt PI}, which is a different symbol than {\tt Pi} or {\tt pi}.

\bigskip
\bigskip

{\bf Example 3}. {\large\sf Compute the derivative of
$y=\dd\frac{3x^4}{(x+1)^2}+\sin 2x + e^{x}\cos 3x$ and check the
answer in maple}.

{\bf Solution}: The hand solution uses the quotient rule, chain rule
and product rule. Let $y=y_1+y_2+y_3$, where
$y_1=\dd\frac{3x^4}{(x+1)^2}$, $y_2=\sin 2x$ and $y_3=\dd e^x\cos
3x$. Then
$$\begin{array}{lclcl}
y_1' &=& \dd\frac{(\mbox{top})'(\mbox{bot})-(\mbox{top})(\mbox{bot})'}{(\mbox{bot})^2}
     &=& \dd\frac{12x^2(x+1)^2-6x^2(x+1)}{(x+1)^4}\\[2ex]
y_2' &=& \dd 2\cos 2x \mbox{~by the chain rule} \\[1ex]
y_3' &=& \dd (\mbox{first})'(\mbox{second})+(\mbox{first})(\mbox{second})'
     &=& \dd e^x\cos 3x - 3e^x\sin 3x.
\end{array}
$$
The code for maple:
\begin{verbatim}
 y1:=3*x^4/(x+1)^2: y2:=sin(2*x): y3:=exp(x)*\cos(3*x):
 y1prime:=diff(y1,x);
 y2prime:=diff(y2,x);
 y3prime:=diff(y3,x);
 yprime:=y1prime+y2prime+y3prime;
\end{verbatim}
The displayed answer for $y'$:
$$12\,{\frac {{x}^{3}}{ \left( x+1 \right) ^{2}}}-6\,{\frac {{x}^{4}}{
 \left( x+1 \right) ^{3}}}+2\,\cos \left( 2\,x \right) +{e^{x}}\cos
 \left( 3\,x \right) -3\,{e^{x}}\sin \left( 3\,x \right) $$

{\bf Example 4}. {\large\sf Given $z=2y+xy+(3x+4y)^2$, compute
$\dd\frac{\partial z}{\partial x}$ and $\dd\frac{\partial
z}{\partial y}$ and check the answer}.

{\bf Solution}: By hand, using the chain rule, $\dd\frac{\partial
z}{\partial x}=0+y+6(3x+4y)$ and $\dd\frac{\partial z}{\partial
y}=2+x+8(3x+4y)$. The maple answer check:
\begin{verbatim}
 z:=2*y+x*y+(3*x+4*y)^2:
 dzdx:=diff(z,x);dzdy:=diff(z,y);
\end{verbatim}

{\bf Example 5}. {\large\sf Compute the Jacobian matrix
$\left(\begin{array}{ll} \partial_x z_1& \partial_y z_1 \\
\partial_x z_2 & \partial_y z_2 \end{array}\right)$ and its
determinant $\left|\begin{array}{ll} \partial_x z_1& \partial_y z_1
\\ \partial_x z_2 & \partial_y z_2 \end{array}\right|$ at $x=y=0$}:

{\large\sf $$ z_1=(3x+y+1)^2,\quad z_2=xy+2x+3y$$}

{\bf Solution}: The hand solution:
$$\begin{array}{lclclcl}
a &=& \dd\partial_x z_1(0,0)&=&\dd\left. 6(3x+y+1)\right|_{x=y=0} &=& 6,\\
b &=& \dd\partial_y z_1(0,0)&=&\dd\left. 2(3x+y+1)\right|_{x=y=0} &=& 2,\\
c &=& \dd\partial_x z_2(0,0)&=&\dd\left. (y+2+0)\right|_{x=y=0} &=& 2,\\
d &=& \dd\partial_y z_2(0,0)&=&\dd\left. (x+0+3)\right|_{x=y=0} &=& 3.
\end{array}
$$
Then
$$ \mbox{Jacobian}(0,0)=\left(\begin{array}{cc} a&b \\ c& d\end{array}\right)
=\left(\begin{array}{cc} 6&2\\ 2&3\end{array}\right),$$
$$ \det(\mbox{Jacobian})(0,0))=\left|\begin{array}{cc} a&b \\ c& d\end{array}\right|
=ad-bc=18-4=14.$$
The code for maple:
\begin{verbatim}
 z1:=(3*x+y+1)^2: z2:=x*y+2*x+3*y:
 J:=VectorCalculus[Jacobian]([z1,z2],[x,y]);
 DJ:=LinearAlgebra[Determinant](J);
 subs(x=0,y=0,J);
 subs(x=0,y=0,DJ);
\end{verbatim}
The answers from maple:
$$a=18x+6y+6,\quad b=6x+2y+2,\quad c=y+2,\quad d=x+3, \quad J=\left(\begin{array}{cc} 18x+6y+6 & 6x+2y+2\\ y+2&x+3\end{array}\right),$$
$$
DJ=18x^2+48x+12y+14-2y^2,\quad
J(0,0)=\left(\begin{array}{cc} 6&2\\ 2&3\end{array}\right),\quad
\det(J)=\left|\begin{array}{cc} 6&2\\ 2&3\end{array}\right|=14.$$



{\bf Example 6}. {\large\sf Get \MAPLE{} help}.

{\bf Solution}:  Get help on maple's {\em unapply} function by entering \fbox{\tt
?unapply} into a \MAPLE{} worksheet. The question mark precedes the maple keyword.
All maple help has examples, normally at the end of the help sheet. Here are some keywords to try:
\begin{quote}\tt
unapply, plot, expand, factor, ifactor, solve, fsolve, array, set, for, do, parse,
plot3d, dsolve, int, diff, newuser, exp, sin, cos, tan, sinh, cosh, ln, log
\end{quote}

\bigskip

{\bf Example 7}. {\large\sf Run the \MAPLE{} tutorial in \MAPLE{}
versions 6 to 18}.

{\bf Solution}: In a \MAPLE{} worksheet, enter \fbox{\tt ?newuser} and
choose the {\em New User's Tour}. In the tour, you will learn some basics
of \MAPLE{}. See the course web site links for other tutorials and reference cards. The {\em Utah Maple Tutorial} has example code that applies to this course.
\bigskip

{\bf End of Maple Lab 1.}

\end{document}
