MatLab Handouts (2) --- Vectors, Matrices, Matrix
Algebra and MatLab Function rref
Here is just a reminder on how to start the MatLab.
If you are using a PC in one of the computer labs on campus, click on
CITNOV1 or Connect to CITNOV1. Type Lab as
NetWare login name and click on Ok key. Click on
CITNOV1 Programs and then click on Matlab icon.
If you are using a PC which does not show the connection to
CITNOV1 on the screen, then you may have to complete the following
sequence of clicks to start the MatLab.
Network Neighborhood
Citnov1
SOFTWARE on Citnov1
WinSW
Matlab
Bin
Matlab.exe
If this is your own PC, you may create a short cut for
MatLab now so that you do not need to go through these clicks
next time.
In MatLab, an N-dimensional row vector is considered as a
1xN matrix, and an N-dimensional column vector is considered as
an Nx1 matrix. Hence, the discussion of vector operations is included in
the discussion of matrix operations.
- Initialize an mxn Matrix:
To enter a 3x4 matrix A, a 4x1 column vector B and a 1x3 row vector C,
we type the following:
>> A=[1 2 0 4;3 -1 1 2;0 2 0 -1];
>> B=[2;1;-1;3];
>> C=[2 1 1];
The (i,j)th element of a matrix can also be assigned or changed
individually. For example, the command A(2,3)=0 replaces
the element at the second row and the third column of matrix A by 0.
- Matrix Operations:
Matrix operations in MatLab are very much like those given
in linear algebra. For example,
A+B, 2*A-3*B (for 2A-3B), A*B (for AB)
A^k (for Ak, k is a given real number), A' (for AT)
- Symbolic Matrix Computation:
The MatLab (version 5) (installed in the PC Lab
at the first floor of Grimsley Hall and the PC Lab in 210 of Capers
Hall) and the Student Edition (version 5) also do symbolic computation.
Here are a few commands for symbolic matrix operations.
- Initialize an mxn Matrix:
To enter a 4x2 matrix T, we type the following:
>> T=sym('[a b;c d;e f;g h]');
- Symbolic Matrix Operations:
Commands for symbolic matrix operations are a little bit complicated
than those for numerical matrix operations as expected. For example,
symadd(A,B) (for A+B), symmul(A,B) (for AB)
sympow(A,k) (for Ak, k is a given positive integer),
transpose(A) (for AT)
To see how MatLab does symbolic computation, you may look at the
MatLab demo on Symbolic Math.
In MatLab, type demo. After getting in
the MatLab
EXPO Main Map, click on Toolboxes on the window bar and
select Symbolic Math Transformations or
Symbolic Math Calculus. You may also type help
toolbox\symbolic in MatLab
to see a list of functions for Symbolic Toolbox.
Reduced Row Echelon Form of an Augmented Matrix:
MatLab function rref finds the reduced row echelon
form for a given matrix. For example, consider the problem of
solving system: Ax=b.
>> A=[1 2 3;4 5 6;7 8 9];
>> b=[1;1;1];
>> rref([A b])
ans = 1 0 -1 -1
0 1 2 1
0 0 0 0
Now we know this system has infinitely many solutions where
x3 is a free variable. The solutions are:
x1=-1+t, x2=1-2t, x3=t, where t is a real number.
Type help rref (in MatLab) to learn more about this command.
Save Computation Results in Text into a File
You need a disk if this is not your own PC. If you are using a PC
in a computer lab, then you can also temporarily save a file on
C Drive under directory
my document. If you are planning to save some of
your computation results, you may do the following after starting the
MatLab.
>> cd a:\
Now you are on A Drive (insert your disk first), or
>> cd c:\mydocu~1
Now you are on C Drive under directory mydocu~1 (a short for
My Document).
diary file_name causes a copy of all subsequent terminal input
and most of the resulting output to be written on the named
file. diary off suspends it. diary on or diary
file_nameturns it back on.