Satyagopal Mandal
Department of Mathematics
University of Kansas
Office: 624 Snow Hall  Phone: 785-864-5180


  • e-mail: mandal@math.ku.edu
  • © Copy right Laws Apply. My Students have the permission to copy.

    Notes on MATLAB

    After you login, you type matlab and return , you will be in matlab.
    Here are some matlab instructions:
    1. The matlab prompt is >> .
    2. If you write 2+3 on the prompt and return the matlab will write ans=5. If you write x=2,y=3, x+y and return, the matlab will return x=2,y=3, ans=5.
    3. To multiply 2 and 3 you write 2*3 and the rest is as above. To compute 2/3 write 2/3 or 3\2.
    4. Write 2^3 and return to compute 2 to the power 3. Write 2^{-3} and return to compute 2 to the power -3.
    5. If you write [1,2,3;4,5,6;7,8,9] the matlab understands the matrix
      123
      456
      789

      If you write A=[1,2,3;4,5,6;7,8,9] matlab remembers that the name of the above matrix is A . It will remember this until you use A to denote something else.

    6. To multiply two matrices A, B write A*B and similarly you add and subtract. If matrices are not "compatible" for addition or multiplication it will give error message.
    7. To find the inverse of a A write A^(-1). You can also write I=[1,0,0;0,1,0;0,0,1] (when A is 3 x 3-matrix) and write A\I or I/A. If the matrix is not invertible you will get error message or something funny.
    8. To solve a system of linear equation AX=b where A is a matrix and X is column vector of unknown variables x1,x2,... and b is a column vector you write
      A\b
      and "it works". If there is no solution you will get some error message or someting funny.

    More on Matlab

    1. To compute the determinant of a matrix A write det(A). This will also help you to see if A is nonsingular (i.e. invertible) or singular (i.e. not invertible). Hence you can use this to check if 3 of 3-vectors are linearly independent or not.
    2. To find the eigen values of A write eig(A).
    3. To find the eigen values and the corresponding eigen vectors, write [V,D]=eig(A). Matlab will give you a matrix V and a diagonal matrix D . The diagonal entries of D are the eigen values of A and the columns of V are the corresponding eigen vectors of A.
    4. To find squareroot of 2 write sqrt(2).