\magnification=\magstep3
\input format
\def\mat{{\tt Matlab\ }}
\def\hb#1{\hfill\break\noindent{\tt #1}\hfill\break\noindent}

\medskip\noindent{\bf General}
To start 
make a new directory named, say, matlab, enter that directory in, at least,
two different windows. You will use one window to run \mat, and the other in
order to edit your .m files (see below).
In the first window type
\hb{matlab}
You are running your main program (which you quit with {\tt quit})\ .
\mat is interactive: whenever you hit
the {\tt return} key, \mat will display all variables that
either have been defined, or have been altered, since the last {\tt return}.
Furthermore, \mat will show you all intermediate values of these variables,
if several changes had occured in their values. 

Commands are separated by either a comma, or a {\tt return} (or both).
Using comma allows you to put several commands on the same line, and also to 
postpone the printing of output. Semi-colon is the same as comma, but
supresses the printing. Try to type
\hb{A=1, B=2}
and then
\hb{A=3; B=2;}

You do not need, and in most cases, you do not want, to type your entire
program on-line: \mat allows you to use subroutines. All subroutines
are called {\tt .m files}\ . These are files that end with the suffix
{\tt .m}\ . They must be located either in your working directory, or be
a part of the package library. For example, in the other window, open
a file named {\tt shalom1.m} and type there
\hb{A=[1 2 3] ; B=2$*$A, C=A.\^{}2}
(and write the file, of course). Then, in the main program window, type
\hb{shalom1}
\mat will try first to find a {\it variable} named {\tt shalom1}\ .
If it finds such, it will print its value; otherwise, it will
look for an .m-file named {\tt shalom1.m} and will execute all its lines.
If you are not pleased with the output, you may edit the .m-file
in the other window, and re-execute it by retyping its name in the main
window. So, big chunks of your program can be stored is such .m-files,
which are called {\it script files}. The variables in the script-files
are identical to those of the main program. Thus, if you type now
\hb{A}
you will get the vector $A$ printed on the screen. You can call one
.m-file from another file. script files are particularly useful for
input data.


There is another type of .m-files called {\it function files} They will be
explained later on. Had I wanted {\tt shalom1.m} to be a function .m-file,
I would have had to have its first line look like, for example,
\hb{\tt function val=shalom1(x,y,z)}
Thus, all .m files that do not start with the word {\tt function}, are treated
as script files.

\medskip\noindent{\bf Input}

Each variable in \mat is either a string of characters, or a matrix. Thus,
\hb{A=11}
declares $A$ to a $1\times 1$ matrix whose single entry equals $11$.
It is the same as
\hb{A=[11]}
A row vector is entered as follows
\hb{B=[7  9.2 -36 78]}
and a column vector can be either entered as
\hb{C=[7;  9.2; -36; 78]}
or
\hb{C=[7  9.2 -36 78]'}
(since {\tt M'} is the transpose of {\tt M}), or
\obeylines{
\hb{C=[7  
	   9.2 
	   -36 
	   78]}
	   }
Here is an example were I input a $3\times 3$ matrix $D$:
\hb{D=[12.1 0 7;12 1+2i 7; 12 13 14]}
Variables in \mat need not be declared. Thus, the fact that $D$ is a 
$3\times 2$ 
matrix was understood by \mat when you entered that matrix. If you want now
to multiply the matrix $D$ by its transpose $D'$, type
\hb{E=D$*$D'}
However, if you want the product to be computed {\it pointwise} and not
as matrix multiplication, type
\hb{F=D.$*$D'}
if you want to generate to large random $R$ matrix for experimentations, simply
type
\hb{R=rand(m,n)}
with $m,n$ the number of rows, columns that you desire. Entries in matrices are
referred to as in $R(4,3)$. If you type
\hb{R(10,3)=13}
and there are less than 10 rows and/or less than 3 columns in $R$, the matrix
$R$ will be expanded, with all new entries are $0$. You may, then, define
a new, $4\times 3$, zero matrix $N$, by typing
\hb{N(4,3)=0}
(there are other way to generate a zero matrix).

There are easy ways to generate vectors:
\hb{T=[5:12]}
even
\hb{TT=[12:-.5: -1]}
and then
\hb{Cos=cos(TT)}

\medskip\noindent{\bf Plotting}

Suppose that we want to plot
$$x^3-2x^2-2x+6$$
on the interval $[-2,4]$. First,
\hb{X=[-2:.1:4];}
generates the point on the $X$-axis. Then,
\hb{Y=X.\^{}3-2$*$X.\^{}2-2$*$X+6;}
generates the $Y$ values. Then
\hb{plot(X,Y)}
generates the graph.
\bye

point 2: every argument that is computed is displayed

>>A=1
  A= 
	1
to avoid type
>>A=1;

point 3: every argument is a matrix. a number is a $1\times 1$ matrix,
a vector is a $1\times n$ matrix or $n\times 1$ matrix. Thus 
C=A*B
can be mutiplication of two numbers, multiplication of two vector (i.e.,
the scalar product of the two vectors, or multiplication of two matrices.


point 4: no space declarations should be made in advance. If you write
A=.....
matlab will check the kind of `animal' that you are labelin as `A', and will
generate the right array for that. there is no discitction between real,
integer, etc.

point 5: arithemtic operations: $+$, $-$, $*$, / , $\bks$, \^{}

point 6: very important: if you write
A=B\^{}2
matlab will interpret that as `A=B*B' and will multiply the two matrices
by matrix multiplication. Sometimes, you may only wish to
square each of the entries of B. In the same manner, if you write
A=B*C
and B, C are two row vectors, and you had meant to multiply
their entries one by one, matlab will complain: it interprets `*'
as matrix multiplication, and as so, you simply cannot multiply
two row vectors. The solution:
A=B.\^{}2
A=B.$*$C
this is pointwise multiplication.
of course, for addition and subtraction there is no difference between
+ and
.+



point 7: .m files: matlab is interactive, and reacts to every line you type
with a possible output. Sometime, however, you wish to write your program
and onyl then to run it. Simply open a file with a suffix .m, say,
junk.m
in the same directory where you run matlab. Then, enter matlab,
do whatever you want, (e.g., define more variables, do some initial
computations etc.) At the time when you need the lines of the .m file 
junk.m, simply type
junk
and matlab will execute, in order, all the lines of junk.


point 8: function files.





point 8: entering info

A=1
and
A=[1]
is the same

A=[2:7]
and
A=[2 3 4 5 6 7]
is the same



\bye
