matrices/slides.org
changeset 394 1a79f9ee7f5c
parent 307 1a73dddb1d05
equal deleted inserted replaced
393:f99254fc7d70 394:1a79f9ee7f5c
    40   - Norm of matrix
    40   - Norm of matrix
    41   - Singular Value Decomposition of matrices
    41   - Singular Value Decomposition of matrices
    42 
    42 
    43 * Creating a matrix
    43 * Creating a matrix
    44   - Creating a matrix using direct data
    44   - Creating a matrix using direct data
    45   : In []: m1 = matrix([1, 2, 3, 4])
    45   : In []: m1 = array([1, 2, 3, 4])
    46   - Creating a matrix using lists
    46   - Creating a matrix using lists
    47   : In []: l1 = [[1,2,3,4],[5,6,7,8]]
    47   : In []: l1 = [[1,2,3,4],[5,6,7,8]]
    48   : In []: m2 = matrix(l1)
    48   : In []: m2 = array(l1)
    49   - A matrix is basically an array
    49 * Exercise 1
       
    50   Create a (2, 4) matrix ~m3~
       
    51   : m3 = [[5,  6,  7,  8],
       
    52   :       [9, 10, 11, 12]]
       
    53 * Solution 1
       
    54   - m3 can be created as,
    50   : In []: m3 = array([[5,6,7,8],[9,10,11,12]])
    55   : In []: m3 = array([[5,6,7,8],[9,10,11,12]])
    51 
    56 
    52 * Matrix operations
    57 * Matrix operations
    53   - Element-wise addition (both matrix should be of order ~mXn~)
    58   - Element-wise addition (both matrix should be of order ~mXn~)
    54     : In []: m3 + m2
    59     : In []: m3 + m2
    55   - Element-wise subtraction (both matrix should be of order ~mXn~)
    60   - Element-wise subtraction (both matrix should be of order ~mXn~)
    56     : In []: m3 - m2
    61     : In []: m3 - m2
    57 * Matrix Multiplication
    62 * Matrix Multiplication
    58   - Matrix Multiplication
    63   - Element-wise multiplication using ~m3 * m2~
    59     : In []: m3 * m2
    64     : In []: m3 * m2
       
    65   - Matrix Multiplication using ~dot(m3, m2)~
       
    66     : In []: dot(m3, m2)
    60     : Out []: ValueError: objects are not aligned
    67     : Out []: ValueError: objects are not aligned
    61   - Element-wise multiplication using ~multiply()~
       
    62     : multiply(m3, m2)
       
    63 
    68 
    64 * Matrix Multiplication (cont'd)
    69 * Matrix Multiplication (cont'd)
    65   - Create two compatible matrices of order ~nXm~ and ~mXr~
    70   - Create two compatible matrices of order ~nXm~ and ~mXr~
    66     : In []: m1.shape
    71     : In []: m1.shape
    67     - matrix m1 is of order ~1 X 4~
    72     - matrix m1 is of order ~1 X 4~
    68   - Creating another matrix of order ~4 X 2~
    73   - Creating another matrix of order ~4 X 2~
    69     : In []: m4 = matrix([[1,2],[3,4],[5,6],[7,8]])
    74     : In []: m4 = array([[1,2],[3,4],[5,6],[7,8]])
    70   - Matrix multiplication
    75   - Matrix multiplication
    71     : In []: m1 * m4
    76     : In []: dot(m1, m4)
    72 * Recall from ~array~
    77 * Recall from ~array~
    73   - The functions 
    78   - The functions 
    74     - ~identity(n)~ - 
    79     - ~identity(n)~ - 
    75       creates an identity matrix of order ~nXn~
    80       creates an identity matrix of order ~nXn~
    76     - ~zeros((m,n))~ - 
    81     - ~zeros((m,n))~ - 
    84   Can also be used with matrices
    89   Can also be used with matrices
    85 
    90 
    86 * More matrix operations
    91 * More matrix operations
    87   Transpose of a matrix
    92   Transpose of a matrix
    88   : In []: m4.T
    93   : In []: m4.T
    89 * Exercise 1 : Frobenius norm \& inverse
    94 * Exercise 2 : Frobenius norm \& inverse
    90   Find out the Frobenius norm of inverse of a ~4 X 4~ matrix.
    95   Find out the Frobenius norm of inverse of a ~4 X 4~ matrix.
    91   : 
    96   : 
    92   The matrix is
    97   The matrix is
    93   : m5 = matrix(arange(1,17).reshape(4,4))
    98   : m5 = arange(1,17).reshape(4,4)
    94   - Inverse of A, 
    99   - Inverse of A, 
    95     - 
   100     - 
    96      #+begin_latex
   101      #+begin_latex
    97        $A^{-1} = inv(A)$
   102        $A^{-1} = inv(A)$
    98      #+end_latex
   103      #+end_latex
   100     - 
   105     - 
   101       #+begin_latex
   106       #+begin_latex
   102         $||A||_F = [\sum_{i,j} abs(a_{i,j})^2]^{1/2}$
   107         $||A||_F = [\sum_{i,j} abs(a_{i,j})^2]^{1/2}$
   103       #+end_latex
   108       #+end_latex
   104 
   109 
   105 * Exercise 2: Infinity norm
   110 * Exercise 3 : Infinity norm
   106   Find the infinity norm of the matrix ~im5~
   111   Find the infinity norm of the matrix ~im5~
   107   : 
   112   : 
   108   - Infinity norm is defined as,
   113   - Infinity norm is defined as,
   109     #+begin_latex
   114     #+begin_latex
   110        $max([\sum_{i} abs(a_{i})^2])$
   115        $max([\sum_{i} abs(a_{i})^2])$