Connecting to to Matlab
The matlab prompt looks like this: >>
Using Matlab
>> A = [1,4,-6
7,6,2
-2,1,0]
You can also separate elements with a space and end each row with a semi-colon like this:
>> A = [1 4 -6; 7 6 2; -2 1 0;]
In either case you have defined the same 3 by 3 matrix named A and you can use it at any time in a calculation or to define another matrix by using its name (A).
Examples: >> B = [2 -4 7 ] B is a 1 by 3 row matrix
![]()
>> C = [2; -4; 7; ] C is a 3 by 1 column matrix
![]()
>>D = [ 5,8,-2;3,-4,5] D is a 2 by 3 matrix
![]()
>> A(1,1) = -5 changes the element in row1 column1 of matrix A to -5
>> D(2,3) = 0 changes the element in row2 column3 of matrix D to 0
>> X=A(1:3,3) this will extract the third column of A (rows 1-3) and put it into a matrix called X.
Examples:
>> A + A adds the matrix A to itself.
>> B * C multiplies B and C
>> C*B - A A is subtracted from the product of C and B
The symbol ^ (above the number 6) is used to raise a matrix to an exponent as follows:
>> A^3 cubes the matrix A ( you might also use A*A*A for the same calculation)
>> C*D an error message is displayed Matlab will give an error message when the calculation cannot be done because of a dimension mismatch.
quit or exit either of these closes the program and ends your matlab session.
save filename this command will save all variables that you have defined in the current session. This is helpful when you enter large matrices that you want to work with at a later date.
load filename this command loads the variables that you saved in a previous session.
diary filename if you are using a Unix terminal, you must use this command before you can print your work. The file you create will be saved in your home directory.
diary off the diary file starts at the point where you insert the command diary and ends where you type diary off. (This allows you to control what gets saved in the diary file.)
lpr this is the command used to print your diary file. EXIT THE MATLAB
PROGRAM.
At the osf1 prompt, type: lpr -Pst220 filename
(note: st220 is the printer in ST I room 220. At other locations you
will use another printer name after the -P )
who displays variables you have defined in your current session
why matlab answers the question.(again and again)
clear clears all variables from your current session. Only use this command if you want to lose everything.
% this is used for comments. Matlab ignores any line that begins with %
>> size(A) gives the dimension of the matrix A
>> inv(A) calculates the inverse of the matrix A , if it exists.
>> det(A) calculates the determinant of the matrix A
>> rref(A) calculates the row reduced echelon form of the matrix A
>> rrefmovie(A) shows the individual pivot operations of rref(A)
>> A' forms the transpose of the matrix A.
>> eye (2,2) this is the 2 by 2 identity
>> zeros (3,3) builds the zero matrix of any dimension
>> ones (3,2) fills a matrix of any size with ones.
augmented matrix you can create an augmented matrix from two others that you have
already defined as follows:>> S = [ A C] uses the matrix A and C defined previously and
creates the matrix S

>> rats(A) displays elements of the matrix A as fractions. Be aware that this command changes the dimension of your matrix. Best used after all calculations have been completed.
>> format long displays all numbers with 15 digits instead of the usual 4 digits
>> eig(A) gives the eigenvalues of the matrix A
>> poly(A) gives the coefficients of the characteristic polynomial A. The roots of this polynomial are the eigenvalues of A.