\documentclass{article}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{enumerate}
\usepackage{ifthen}
\usepackage{ulem} % for strikethrough \sout{...} command
\usepackage{color}
\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{-0.5in}
\setlength{\topmargin}{-0.5in}
\setlength{\headheight}{0.0in}
\setlength{\headsep}{0.0in}
\setlength{\topskip}{0.0in}
\setlength{\textheight}{10in}
\setlength{\textwidth}{7.5in}

\usepackage{tikz,pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{arrows.meta}


\newcommand{\bdot}{\, {\scriptstyle{\bullet}} \,}
\newcommand{\B}[1]{{\bf {#1}}}
\newcommand{\la}{\langle}
\newcommand{\ra}{\rangle}

\newcommand{\myspace}{\parbox[c][0.2in]{0.2in}{\hfill}}
\newcommand{\varspace}[2]{\mbox{\parbox[c][#1]{#2}{\hfill}}}
\newcommand{\force}{{$\mbox{\,\!}$}}

\usepackage{enumitem}

\begin{document}

\pagestyle{empty}

\noindent
\parbox{1.5in}{\bf Math 1120}
\hfill {\Large \bf Maple Tips \& Tricks} \hfill
\parbox{1.5in}{\bf \hfill Supplement}

\vspace{0.1in}

\noindent
Maple is a {\bf Computer Algebra System} (CAS). It can do everything a graphing calculator can do and a whole lot more. 

There are two main ways of interacting with Maple: worksheet mode or document mode. Documents look like and behave much like Microsoft Word documents. Worksheets are the older of the two interfaces. I will be using worksheets since they clearly delineate between text/description and computation. In a worksheet ``{\color{red}\verb|[>|}'' is a command prompt whereas (empty) text boxes look like ``[''.

\vspace{-0.1in}

\begin{itemize}[leftmargin=*] \setlength\itemsep{0pt}
\item To get a new command prompt press the \verb|[>| button. For a new text box press the T button.\\ {} [Both are located along the top ribbon.]

\item \fbox{F5} toggles the input mode between math mode and text mode. You can also switch by clicking \fbox{Text} or \fbox{Math}.

When you input in text mode at a command prompt {\color{red}\verb|commands are in red text|} and not pre-formatted. In math mode, Maple pre-formats expressions. For example, in text mode typing \verb|x| then \verb|^| then \verb|2| yields {\color{red}\verb|x^2|} whereas in math mode we would see $x^2$.

I prefer typing in text mode where what you see is what you typed. Whereas math mode easily hides errors. If your code isn't working correctly, debugging math mode formatted commands can be much much harder.

\item \fbox{Enter} executes commands at a command prompt. \fbox{Shift}+\fbox{Enter} gives a new line at a command prompt (without executing the command). Generally when a command is executed, it makes a change to memory. Sometimes the after the command is executed Maple will print some {\color{blue}blue output} to indicate what it did.

{\bf Be careful:} Commands are affected by what Maple currently has stored in Memory. If you jump around and execute commands out of order, you may get undesired results. Maple does not care about how you've ordered commands in your file. It just cares about the order of their execution!

\item Lines of code end with either a colon ``:'' or a semicolon ``;''. A colon signals that Maple should suppress output (although it will still show certain warnings and errors) whereas a semicolon tells Maple to go ahead and display any relevant output (usually printed in {\color{blue}blue} below the command prompt).

\item Executing {\color{red}\verb|[> ? topic|} will cause Maple to lookup help on {\color{red}\verb|topic|}. Of course, you can also use the Help menu. While Maple has extensive help, its help pages are rather uneven. Please keep in mind that Maple is quite popular, so you are likely to find what you need by Googling around. 

\item {\color{red}\verb|[> restart;|} clears memory. I like to put this at the beginning of various sections of my worksheets.

\item {\color{red}\verb|[> with(PACKAGE):|} loads {\color{red}\verb|PACKAGE|} into memory. Notice the colon. If you use a semicolon, Maple will list off all of the procedures you just loaded. Packages I use often: 

\vspace{-0.1in}

\begin{itemize}[leftmargin=*] \setlength\itemsep{0pt}
\item {\color{red}\verb|[> with(plots):|} loads various plotting commands like the {\color{red}\verb|display|} command which allows one to put various plots together in one picture. 
\item {\color{red}\verb|[> with(LinearAlgebra):|} loads various matrix and other linear algebra tools. You might run into the old linear algebra package {\color{red}\verb|linalg|}. You probably want to avoid using this old package since it's no longer fully supported.
\item {\color{red}\verb|[> with(VectorCalculus):|} loads a bunch of multivariable calculus tools. [I use this in all my Calculus 3 stuff.]
\end{itemize}

\vspace{-0.05in}

\item Assignment versus equations: {\color{red}\verb|a = 5|} is an equation and essentially asks ``Is $a$ equal to $5$?'' On the other hand, {\color{red}\verb|a := 5|} assigns the value $5$ to the variable named {\color{red}\verb|a|}.

\item {\bf Important Warning:} Maple is case sensitive. For example, {\color{red}\verb|A|} and {\color{red}\verb|a|} are different variables. When someone is stuck and Maple isn't working, I often find that they have misspelled or miss-capitalized a command. 

\item {\bf Important Warning:} Maple {\it forgets everything} when it is shutdown. If you save your file, shutdown Maple, and then reopen your sheet, you will still see {\color{blue}blue computation outputs} from previous computations. This does not mean that Maple remembers these results. So just because you at some point in the past executed {\color{red}\verb|[> a := 5;|} and you see {\color{blue}$a := 5$} displayed below it, does not mean Maple still remembers this. I like to refer to the {\color{blue}blue} output as ghosts of computations past.

Probably more than 9 out of 10 problems I see with Maple are solved by going {\bf back to the beginning of a worksheet and re-executing everything}. 

On a related note, if we type {\color{red}\verb|[> mycommand(1,2,3);|} and Maple returns ``{\color{blue}mycommand(1,2,3);}'', that is Maple's way of admitting it doesn't know what you're talking about (it just repeats back exactly what you told it). If this happens, double check your command's spelling/capitalization. Then make sure you reexecuted all {\color{red}\verb|with|} commands when you reopened your worksheet.

\item Most arithmetical and standard functions have unsurprising symbols and names: {\color{red}\verb|+ - * / ^|} are add, subtract, multiply, divide, and exponentiate. {\color{red}\verb|sin(x) cos(x) tan(x) sec(x) csc(x) arcsin(x) ln(x)|} are sine, cosine, tangent, secant, cosecant, arcsine (i.e., inverse sine) and natural log. 

{\bf Important Warning:} The exponential function $e^x$ is {\color{red}\verb|exp(x)|}. If you type \verb|e^x|, Maple will raise the variable \verb|e| to the variable \verb|x| power -- almost certainly, this is something you'll never want to do.  Accidentally typing \verb|e^x| instead of \verb|exp(x)| is one of the {\it most common mistakes} I see.

\item {\bf Important Warning:} The mathematical constant $\pi \approx 3.14159265$ is {\color{red}\verb|Pi|} in Maple. On the other hand, {\verb|pi|} is the variable lowercase Greek letter $\pi$. Capitalization matters! Forgetting to capitalize pi is another {\it very common mistake}.

\item Maple by default works with exact symbolic expressions. Commands like {\color{red}\verb|evalf|} tell Maple to give us a decimal approximation (the f in evalf stands for {\it floating point} approximation). For example, {\color{red}\verb|[> evalf(sqrt(5));|} will return an approximation of $\sqrt{5}$ with 10 digits of accuracy. Likewise, {\color{red}\verb|[> evalf(Pi, 1000);|} will give a 1,000 digits of $\pi$.

\item Wrapping commands in the {\color{red}simplify} command is often a good idea: {\color{red} \verb|[> simplify(STUFF);|}

\item Maple has context sensitive menus. In older versions, if you right-click on some {\color{blue}blue output}, Maple will pop-up a menu with a selection of suggested (hopefully relevant) commands. Starting in Maple 2019, if you right-click, the last option is ``Open Context Panel for more\dots''. This will open a side panel with a list of commands you can perform. For example, if I execute {\color{red}\verb|[> x^2+3*x-6=0;|} and click on the blue output: {\color{blue}$x^2+3x-6=0$} (with the context panel open), then I get choices like ``Differentiate'' and ``Solve'' in the context panel. 

\item To solve an equation using a context panel you can use Solve$\to$Solve, Solve$\to$Numerically Solve, or Solve$\to$Numericall Solve from point (among other options). If you give Maple an expression instead of an equation, it will try to solve that expression set equal to zero.

Solve$\to$Solve is the general solver. The associated command is {\color{red}\verb|solve(EQUATION TO SOLVE)|}. This solver will try to find all possible {\it exact symbolic} solutions. Note that sometimes solve returns nothing. This does not mean that there are no solutions. It just means Maple couldn't find any. 

Solve$\to$Numerically Solve looks for approximate solutions. The associated command is {\color{red}\verb|fsolve(EQUATION TO SOLVE)|}. The ``f'' in fsolve stands for floating point. fsolve will try to find all solutions up to a certain number of digits of accuracy. Again, be skeptical. Sometimes fsolve will find no solution or only one solution when there are many solutions.

A variant of numerically solving is Solve$\to$Numerically Solve from point. This time Maple asks for a starting value (essentially a first guess). The associated command is {\color{red}\verb|fsolve(EQUATION TO SOLVE, GUESS)|}. If we are trying to solve really tricky equations and Maple isn't giving us the solution we want, this command allows us to help Maple out. 

\item {\color{red}\verb|[> plot(x^2,x=-1..2);|} creates a plot of $y=x^2$ with domain $-1 \leq x \leq 2$. If we wanted to adjust our plot, there are many plot options. For example, {\color{red}\verb|[> plot(x^2,x=-1..2, color=green, scaling=constrained);|} changes our function's plot to green and doesn't rescale axes.

\item {\bf Functions vs. Expressions:} If we want to define the function $f(x)=x^2$, we use {\color{red}\verb|[> f := x -> x^2;|}. Breaking this down: {\color{red}\verb|x^2|} is the expression $x^2$, {\color{red}\verb|x -> x^2|} is the mapping that sends $x$ to $x^2$. Then {\color{red}\verb|f := x -> x^2;|} assigns the name $f$ to the mapping $x \mapsto x^2$. 

On the other hand, {\color{red}\verb|[> g := x^2;|} just assigns the expression $x^2$ to $g$. If we executed both of these commands, $f$ is a function and $g$ is an expression. This means that if we execute {\color{red}\verb|[> f(2);|} we should expect the output {\color{blue}4}. On the other hand, we need a substitute command {\color{red}\verb|[> subs(x=2,g);|} to plug $x=2$ into $g$. In my example pages you will often see things like,

\vspace{-0.15in}

\hspace*{0.7in}
\begin{minipage}{2in}
{\color{red}\verb|[> f := x -> x^2:|}\\
{\color{red}\verb|   'f(x)' = f(x);|}
\end{minipage}

If executed, these commands return {\color{blue}$f(x)=x^2$}. Notice that the first command ends in a colon so its output is suppressed. This command is the one that actually defines the function. The second command merely prints out our pretty $f(x)=x^2$. Notice the quotes:  {\color{red}\verb|'f(x)'|} this tells Maple just to print out $f(x)$.

\item Differentiation is done with {\color{red}\verb|diff|} and integration is done with {\color{red}\verb|int|}. For example, {\color{red}\verb|[> diff(sin(x), x);|} computes the derivative of $\sin(x)$. Likewise, {\color{red}\verb|[> diff(sin(x), x,x,x);|} computes the third derivative of $\sin(x)$. Similarly, we use the command {\color{red}\verb|[> int(sin(x), x);|} to compute an antiderivative of $\sin(x)$. Note: Maple does not add in the arbitrary constant -- be careful. Finally, {\color{red}\verb|[> int(sin(x), x=-Pi..2*Pi);|} computes the definite integral $\int_{-\pi}^{2\pi} \sin(x)\,dx$.

{\it Note on inert commands:} Many commands have an {\it inert} companion: {\color{red}\verb|diff|} vs. {\color{red}\verb|Diff|}. The only difference between these commands is that Maple actually executes diff while is holds off final execution of Diff. I will often use this to make Maple display integrals. For example, {\color{red}\verb|[> Int(sin(x), x=-Pi..2*Pi) = int(sin(x), x=-Pi..2*Pi);|} when executed displays {\color{blue}$\int_{-\pi}^{2\pi} \sin(x)\,dx=-2$}. The left hand side's \verb|Int| is just printed out while the right hand side's \verb|int| is evaluated.

\item Limits can be computed with {\color{red}\verb|limit|}. Optionally one can specify left- or right-handed limits. For example,\\ {\color{red}\verb|[> limit(1/x,x=0,right);|} computes $\displaystyle \lim\limits_{x \to 0^+} \frac{1}{x}$ and returns {\color{blue}infinity}. Limits to $\pm\infty$ are also allowed. For example, {\color{red}\verb|[> limit(1/x,x=-infinity);|} computes $\displaystyle \lim\limits_{x \to -\infty} \frac{1}{x}$ and returns {\color{blue}0}. 

\vspace{-0.1in}

\item Sums can be computed with {\color{red}\verb|sum|}. For example, {\color{red}\verb|[> sum(k^2,k=1..10);|} computes $\displaystyle\sum\limits_{k=1}^{10} k^2=1^2+2^2+\cdots+10^2=$ {\color{blue}385}.

\vspace{-0.15in}

Likewise, {\color{red}\verb|[> simplify(sum(i,k=1..n));|} computes $\displaystyle\sum\limits_{i=1}^{n} i = 1+2+\cdots+n=$ {\color{blue} $\frac{1}{2}n^2+\frac{1}{2}n$}. The summation command can also handle some infinite series. For example, {\color{red}\verb|[> sum(1/n^2,n=1..infinity);|} is able to compute $\displaystyle \sum\limits_{n=1}^\infty \dfrac{1}{n^2} =$ {\color{blue}$\dfrac{\pi^2}{6}$}.

\end{itemize}

\end{document}


