January 9, 1996
Commands are entered in MATLAB at the command prompt. Case is important so that A and a are different. To supress output add a semi-colon to the end of a statement. Use the arrow keys to scroll back to previous commands and left and right to edit statements.
1. Entering matrices
A matrix is entered by (i) explictly listing elements, (ii) using defining statements (iii) disk files.
Two examples of entering them yourself:
A= [1 2 3; 4 5 6; 7 8 9] B = [ 1 3 5 7 ]create the obvious matrices. The semicolon ; separates rows. Commas can be used insetad of spaces. Do not use spaces between parts of a number, e.g. 2.34e-9 is valid but 2.34 e-9 will be treated as two elements.
Complex numbers are allowed by appending i:
A= [1 2;3 4] + i* [5 6;7 8] A= [1+5i 2+6i;3+7i 4+8i]produce the same matrix. Don't write 2 + 3i as that will produce two numbers. You can use i or j as the number sqrt(-1).
2. Other ways to create matrices
The following matrix operations are allowed:
For powers, multiplication and division, the operators .* ./ .^ all perform elementwise multiplication. A.^ 2 squares each element in A while A^ 2 is the square of A.
These functions operate elementwise on matrices
sin cos tan asin acos atan exp log abs sqrt sign rem (remainder)
These functions operate on vectors to produce a scalar or on a column-by-column fashion to produce a row vector. Use the transpose to get row-by-row operation.
max min sum prod median sort std any all meanmax(max(A)) give the maximum entry in A.
5. Submatrices and colon notation
x=[0.0:0.1:2.0]'; y=sin(x); [x,y]
6. Output format
MATLAB lets you output in various formats. Amond them are the following:
This is just a small subset of all the graphics MATLAB can do.
plot(x,y) This plots the vector y as a function of x. Thus, the following will plot sin(x):
x=-3.14:.1:3.14; y=sin(x); plot(x,y)and the following plots sin(x) and cos(x) on the same plot:
x=-3.14:.1:3.14; y1=sin(x); y2=cos(x); plot(x,[y1;y2])Alternatively you could write the last line as plot(x,y1,y2).
print bobwill produce a file of the plot for printing called ``bob.ps''
8. Recording your work
Type diary filename and everything you type and that MATLAB outputs is recorded in the file called filename. Type diary off to turn it off and diary to turn it back on. Once done with MATLAB, you can print the output.