Maths Tools for Cognitive Scientists Lab 3 (Week 4)

Part a

http://www.informatics.sussex.ac.uk/users/bg22/mtcs/mtcs3a.html

  1. Create matrices in matlab (type the text between angled brackets):

     

  2. Matrix scalar multiplication (and division):

    Every entry of the matrix is multiplied separately by the scalar.


    Multiply the matrix < m3 > by 4 and call it < m4 >.

    Divide < m4 > by 2.

  3.  

  4. Element-by-element multiplication (,division and raising to a power):

    The elements of each matrix are multiplied by the corresponding element in the other matrix
    which must have the same shape.

  5.  

  6. Matrix multiplication:

    Two matrices can only be multiplied if the number of columns in the first is equal to the
    number of rows in the second
    .

    If matrix A has m rows and n columns: A(m,n)
    and matrix B has n rows and p columns: B(n,p)
    then their product, matrix C, has m rows and p columns: A(m,n) x B(n,p) = C(m,p)

    Each element in the first row of A is multiplied by the corresponding element in the
    first column of B and the products added to give the first element of C:

    c11 = (a11*b11 + a12*b21 + a13*b31 + ... a1nbn1)

    Similarly, the next element of C in the first row is given by the sum of the products
    of the elements in the first row of A and the second column of B.

    For example:

    On paper, try multiplying the following pairs of matrices.
    Then check if you are correct using matlab.

     

  7.  

  8. Subscripts: accessing elements of matrices:

    To access an element in row 3 and column 2 of matrix A type < A(3,2) >.

  9.  

  10. Some functions that can be used on matrices:

    < sum >  sums the elements of a matrix column-wise 
    < rot90 > rotate a matrix by 90—
    < flipud > flip matrix upside-down
    < fliplr > flip the matrix left-right
    < diag > extracts matrix elements on the main diagonal
    (top left to bottom right)

     

Now go to Part b