\documentclass[12pt]{article}
\usepackage{graphicx,amsfonts}


\setlength{\oddsidemargin}{0in} \setlength{\evensidemargin}{0in}
\setlength{\textwidth}{6.5in} \setlength{\textheight}{8.5in}
\setlength{\topmargin}{0in}

\begin{document}

\section*{Exercise Set}

This is the set of exercises from the ``Introduction to Matlab''.  You can
use the \LaTeX file online to answer these-  They will be due on Monday, April 9th.
When answering, be sure all your names appear, either as the author or just at the top.

\begin{enumerate}
\item Give the Matlab command (using the colon operator) to create the following array:
$$
4.5\quad 4.0 \quad 3.5 \quad 3.0 \quad \ldots \quad 1.5
$$
\item What does the following do?
\begin{verbatim}
x=[1 2 3 4 5];
y=2.^x;
z=x.*x;
\end{verbatim}
\item Given the array:
$$
A=\left[\begin{array}{rrrrr}
1&2&3&4&5\\
5&1&2&3&4\\
4&5&1&2&3\\
3&4&5&1&2\\
2&3&4&5&1
\end{array}\right]
$$
\begin{enumerate}
\item How do I multiply everything in $A$ by 2, then subtract 3 from every entry (in Matlab)?
\item What is the shortest Matlab command to get a subarray using the following elements:
$$
B=\left[\begin{array}{rrr}
A(1,2) & A(1,3) & A(1,4)\\
A(3,1) & A(3,2) & A(3,3)
\end{array}\right]
$$
\item By hand, what is the transpose of $B$ (from the previous problem)?
\item What is the Matlab command to remove the even-numbered columns of $A$?
\item In Matlab, what does \verb!A-eye(5)! do?
\end{enumerate}
\item How do I create an array that has 4 rows, 6 columns, and is filled
with random numbers between 0 and 1?
\item Watch the 4 minute video ``Working in the Development Environment''
on the Matlab channel in YouTube (Google it).  Then answer the following
questions:
\begin{enumerate}
\item What are two different ways of saving the variables in the workspace?
\item How do you load the variables back into Matlab?
\end{enumerate}
\item Watch the 6 minute video ``Writing a Matlab Program'' in 
the same playlist.
\begin{enumerate}
\item What is a ``script''?  How do you run a script?
\item Write the script that is given in the example, \verb+simple0.m+ (Note the zero 
to distinguish it from the next step).
\item Write the function that is given in the example, and save it as \verb+simple.m+
\end{enumerate}
\item After viewing the previous video, determine what Matlab does if you type 
the following:
\begin{verbatim}
a=1.5; b=3.6;
for k=1:100
   h(k)=(b-a)*rand+a;
end
\end{verbatim}
(Hint:  What is the biggest and smallest possible number in the vector $h$?)

\item Write a script file that will construct a vector $x$ consisting of 225
evenly spaced points in the interval $[-4,8]$, then proceeds to plot
$\sin(x)$ in red, $\sin(2x)$
in black, and $\sin(3x)$ in green, all on the same plot.  

\item When we compute with numbers, we might run into some difficulty 
if the numbers become too large or undefined.  Some examples:
\begin{itemize}
\item \verb+eps+ is the distance from 1 to the next largest number.  That is,
Matlab will see something like \verb^1+eps/2^ as the same as 1.
\item \verb+NaN+ means ``Not a Number''-  Happens if you do something like $1/0$,  and \verb+Inf+ means that the expression is infinitely large.
\end{itemize}
Here are some fun things to try in Matlab-  Tell me what happens in each case:
\begin{enumerate}
\item \verb+eps+  (This is scientific notation), \verb^1-(1+eps/2)^
\item \verb+1/0+, \verb+-1/0+ and   \verb+0/0+
\item \verb+1/Inf+
\item \verb^Inf+Inf^, and  \verb^Inf-Inf^ 
\item \verb+Inf/Inf+ and \verb+Inf/0+
\end{enumerate}

\end{enumerate}
\end{document}