
\documentclass[11pt]{article}
%\usepackage{graphicx}
%\usepackage{amsmath}
%\usepackage{amsfonts}
%\usepackage{amssymb}
\usepackage{times}
\pagestyle{empty}

\addtolength{\textwidth}{1.2in}
\addtolength{\textheight}{1.2in}
\addtolength{\oddsidemargin}{-.58in}
\addtolength{\evensidemargin}{-.58in}
\renewcommand{\baselinestretch}{1.0}
\parindent = 0cm
\parskip = .1cm

%TCIDATA{OutputFilter=latex2.dll}
%TCIDATA{CSTFile=LaTeX article (bright).cst}
%TCIDATA{Created=Mon Aug 27 11:48:44 2001}
%TCIDATA{LastRevised=Fri Sep 21 10:59:46 2001}
%TCIDATA{<META NAME="GraphicsSave" CONTENT="32">}
%TCIDATA{<META NAME="DocumentShell" CONTENT="General\Blank Document">}
%TCIDATA{Language=American English}
\newtheorem{theorem}{Theorem}
\newtheorem{acknowledgement}[theorem]{Acknowledgement}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{axiom}[theorem]{Axiom}
\newtheorem{case}[theorem]{Case}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{conclusion}[theorem]{Conclusion}
\newtheorem{condition}[theorem]{Condition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{criterion}[theorem]{Criterion}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{exercise}[theorem]{Exercise}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{solution}[theorem]{Solution}
\newtheorem{summary}[theorem]{Summary}
\newenvironment{proof}[1][Proof]{\textbf{#1.} }{\ \rule{0.5em}{0.5em}}



\begin{document}

\begin{center}
{\Large Entering formulas in \textsc{\textsc{MatLab}}
\footnote{\copyright 2004 Winfried Just, Department of Mathematics, 
Ohio University.  All rights reserved.}}
\end{center}

\bigskip

In order to start a \textsc{MatLab} session, click on the \textsc{MatLab} icon.  A screen with three windows should appear.  One of these windows is called the ``Command Window.''  This is the one you will be working in.  If for some reason you don't see a command window, go to ``View'' on the menu bar, choose ``Desktop Layout,'' and click on ``Default.''

In the Command Window, you see the symbol

\smallskip

\noindent
\verb$>>$

\smallskip

at the beginning of a line.  This is your prompt.  All commands will be
entered at the prompt.  You enter a command by typing it, and then hitting ENTER.

The simplest type of command you can enter is a number.  Try:

\smallskip

\noindent
\verb$>> 7.2$

\smallskip

After hitting ENTER, \textsc{MatLab} will show you an ``answer'' of \verb$7.2000$.  This is not very exciting.  Here is something more interesting to try:  
Enter

\smallskip

\noindent
\verb$>> pi$


\smallskip

\textsc{MatLab} gives you the numerical value of $\pi$ with a precision of four places after the decimal point.  How can you find the value of $\pi$ with a better precision?  Enter

\smallskip

\noindent
\verb$>> format long$

\noindent
\verb$>> pi$

\smallskip

As you can see, \textsc{MatLab} leaves a lot of blank lines in the output.  This can be annoying, especially if you want to print your output.  In order to suppress the blank lines, enter

\smallskip
\noindent
\verb$>> format compact$

\smallskip

\textsc{MatLab} also can handle symbolic expressions, but a little more care needs to be taken with those.  Try entering

\smallskip

\noindent
\verb$>> x$

\smallskip

\textsc{MatLab} will give you an error message, since no numerical value has yet been assigned to \verb$x$.
You can assign a numerical value to a variable by an \emph{assignment statement}.  Enter

\smallskip

\noindent
\verb$>> x = 6.34;$

\noindent
\verb$>> x$

\smallskip

Now \textsc{MatLab} tells you that the value of the variable \verb$x$ is \verb$6.34$, which makes sense, since this is the value we assigned to this variable.  The semicolon at the end of the assingment 
statement (or any other statement) has the effect of suppressing output.  Note that \textsc{MatLab} did not give you any answer after you entered the assignment statement, it just gave you the next prompt.  See what happens if you leave out the semicolon:

\smallskip

\noindent
\verb$>> x = - .8$

\smallskip

By now you may find it annoying that \textsc{MatLab} gives you all these zeros at the end, and you may want to return to the format where the answers are given just with a precision of four digits after the decimal point.  How can you do this?  You may have guessed by now that you should enter

\smallskip

\noindent
\verb$>> format ``something''$

\smallskip

You may even have guessed what the ``something'' should be, but how can you make sure that your guess was right?  \textsc{MatLab} has two neat ways of telling you how to use its commands.  One way is to use the "Help" feature on the menu bar.  This one is rather self-explanatory, but it may be cumbersome at times.  An often faster way is this:  

\smallskip
 
\noindent
\verb$>> help format$ 

\smallskip

This outputs all the options for the ``format'' command, and you will notice that your first guess about the ``something'' was correct after all!

\bigskip

The symbols for algebraic operations in \textsc{MatLab} are:

\begin{itemize}
\item \verb$+$ for addition, 
\item \verb$-$ for subtraction, 
\item \verb$*$ for multiplication, 
\item \verb$/$ for division,
\item \verb$^$ for exponentiation.  
\end{itemize}

For example, if you want to compute $2\pi$, then you should enter

\smallskip

\noindent
\verb$>> 2*pi$

\noindent

\emph{Under no circumstances are you allowed to omit the $*$ symbol for multiplication!}  Try entering

\smallskip

\noindent
\verb$>> 2pi$

\smallskip

You will get an error message.

For entering more complicated expressions, you need to know how \textsc{MatLab} prioritizes execution of operations.  This works as follows:

\begin{itemize}
\item exponentiation has the highest priority
\item multiplication and division have the second highest priority
\item addition and subtraction have the lowest priority
\end{itemize}

For example, if you enter

\smallskip

\noindent
\verb$>> 2*3^2/3+5$

\smallskip

\textsc{MatLab} will evaluate this as $(2\cdot3^2)/3 + 5 = 11$.  If you want \textsc{MatLab} to evaluate $2\cdot 3^{\frac{2}{3} + 5}$
instead, you need to enter:

\smallskip

\noindent
\verb$>> 2*3^(2/3+5)$

\smallskip

If you want \textsc{MatLab} to evaluate $2\cdot (3^{\frac{2}{3}} + 5)$
instead, you need to enter:

\smallskip

\noindent
\verb$>> 2*(3^(2/3)+5)$

\smallskip

If several operations have the same priority, \textsc{MatLab} executes them from left to right. For example, the expression

\smallskip

\noindent
\verb$>> 6/2*3$

\smallskip

will be evaluated as $\frac{6}{2}\cdot 3 = 9$; if you want \textsc{MatLab} to evaluate $\frac{6}{2\cdot 3}$ instead,
you need to enter:

\smallskip

\noindent
\verb$>> 6/(2*3)$

\smallskip

Invariably, when entering long formulas, you will make occasional mistakes.  Suppose you want to calculate $\frac{\pi}{5 + 2^3} - 13$ and you inadvertently entered

\smallskip

\noindent
\verb$>> pi/(5 + 2^3 - 13)$

\smallskip

\textsc{MatLab} will give you a warning: you should never divide by zero.  It is easy enough to correct your mistake without retyping the whole formula: Hitting the $\uparrow$ key will restore the formula, and then you can easily move the closing bracket into the right place.  In general, you can recover all commands you entered in a given session by using the $\uparrow$ and $\downarrow$ keys.

Please correct the mistake in the formula right now and record the correct answer for possible submission with your first quiz.

If you don't exactly remember \textsc{MatLab}'s rules for prioritizing operations, there is a simple way to aviod possible problems:  Use brackets liberally.  A well-placed pair of brackets never hurts.
 
You can use arithmetic operations on variables as well as numbers.  Try entering:

\smallskip

\noindent
\verb$>> 3/x$

\noindent
\verb$>> 2*y$

\smallskip

While \textsc{MatLab} gives you a numerical answer to the former, the latter results in an error message.  What is going on here?  Recall that earlier in this session, we assigned the value $-0.8$ to the variable \verb$x$, and the answer that \textsc{MatLab} returned to your first command is simply $\frac{3}{-0.8}$.  No value has been assigned to the variable 
\verb$y$ yet, and this is why the second command generates an error message.  You can find out which variables are currently in use by entering

\smallskip

\noindent
\verb$>> who$

\smallskip

Note that one of the variables in use is called \verb$ans$; it is the default variable used by \textsc{MatLab} when no other variable is specified.  You can remove all assignments to any of these variables by entering 

\smallskip

\noindent
\verb$>> clear$

\smallskip

It is highly recommended that you always begin a \textsc{MatLab} session by using this command so that no previous work will interfere with the current session.
 

\end{document}
