MatLab Handouts (2) --- Vectors, Matrices and Matrix Algebra


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.
  1. 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.
  2. 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)
    
  3. 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.

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.
  • Rank of a Matrix:
    MatLab command rank computes the rank of a given matrix. For example,
       >> A=[1 2 3;4 5 6;7 8 9];
       >> rank(A)
       ans = 2
    
    Type help rank (in MatLab) to learn more about this command.

  • Save Computation Results in Text into a File
    You need a disk if you are not using 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_name turns it back on.