Instructions to MatLab (4) --- Vectors and Matrices


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 the same as they are in linear algebra. For example, A+B, A-B, A*B, A^k, A', inv(A) (assume A-1 exists), det(A).