%From ynagel Thu Mar  6 14:51:19 1997
\documentstyle[12pt]{article}
% save paper
 \oddsidemargin 5pt \evensidemargin 5pt \marginparwidth 68pt 
 \marginparsep 10pt \topmargin 10pt \headheight 10pt
 \headsep 15pt \footskip 35pt
 \textheight = 625pt  \textwidth 440pt \columnsep 10pt \columnseprule 5pt 

\begin{document}
\centerline{\Large\bf Matlab Tutorial}

\begin{flushright}
Y. Nagel Mar 97 \\ additions-changes by A.Miller
\end{flushright}


GETTING STARTED
\begin{enumerate}
        \item  Matlab executes a file called {\tt startup.m} when it 
               starts. If you do not have such a file, then it
               uses its defaults for your MATLAB environment. 

        \item Getting Help:
\begin{enumerate}
        \item   typing {\tt help} will show you all matlab commands
        \item   typing {\tt help} {\it command} will give you help with
        a particular command.
\end{enumerate}
        \item If you enter a command then press the RETURN key,
                Matlab will print the answer on your screen. If you
                want to suppress this output, put a semicolon (;)
                after your command.
        \item To save your session and reload it later, type 
\begin{verbatim}
                save <filename>
                load <filename>
\end{verbatim}
The {\tt <filename> } indicates an optional
filename. If I omit it, my work will be saved as matlab.mat. If I 
call it, say {\bf fred}, it will be saved as fred.mat.
        \item To make a transcript of all your commands, then turn it off
              later, type
\begin{verbatim}
                diary <filename>
                diary off
\end{verbatim}

\item  All commands entered at the same session are saved in your
Matlab {\it workspace}. To list the current variables in your workspace,
type {\tt who}
\item To temporarily escape from Matlab and execute a DOS (unix) command,
type an exclamation followed by the command. For example:
\begin{verbatim}
! DIR   - will list files in your current directory  - Windows
! ls    - will list files in your current directory  - unix
! edit <filename> - will edit filename assuming you have an
                    external program edit
\end{verbatim}

\end{enumerate}

SIMPLE MATRIX CALCULUS
\begin{enumerate}
\item Entering Matrices: matlab recognizes several formats for matrices:
\begin{verbatim}
        A=[1 2; 3 4]
        A=[1 2
           3 4]
\end{verbatim}
Yields the same two by two matrix.
\item Some Standard Matrices
\begin{verbatim}
                                                 Minimat
eye(n)    - the nxn Identity Matrix              same
zeros(n)  - the nxn zero matrix                  zeros(n,m)
ones(n)   - the nxn matrix with all ones         ones(n,m)
rand(m,n) - a randomly generated mxn matrix      same
\end{verbatim}
\item Built in Functions
\begin{verbatim}
A'       the conjugate transpose of matrix A
A*B      product of matrices A and B (provided dimensions match)
inv(A)   inverse of matrix A
A^n      is the  n th power of matrix A
poly(A)  is the characteristic polynomial of A
eig(A)   eigen values of A
det(A)   is the determinant of A
trace(A) is the trace of A
\end{verbatim}

\item Scripts and Functions: You can write matlab commands
      into an {\bf M-file} called {\tt something.m}  which
      you can read into your matlab session by just typing
      {\tt something}.
     Here is an example of a function called {\tt invx.m:}
\begin{verbatim}
function B = invx(A)                     % find the inverse of A
 [n n] = size(A); Save=A; B=eye(n);
 for k=1:n
   [y,h] = max(abs(A(k:n,k))); h=k+h-1;  % h is row of next pivot
   A([k h],:) = A([h k],:);              % swap row h and k
   B([k h],:) = B([h k],:);              % do the same row op to B
   c=A(k,k);
   A(k,:) = A(k,:)/c;                    % want A(k,k)=1
   B(k,:) = B(k,:)/c;                    % do same row op to B
   for i = [1:k-1,k+1:n]                 % for each i different from k
      c=-A(i,k);
      A(i,:) = A(i,:) + c*A(k,:);        % want A(i,k)=0
      B(i,:) = B(i,:) + c*B(k,:);        % do same row op to B
   end
 end
 A=Save;
\end{verbatim}
\end{enumerate}
\end{document}

