matrices/slides.org
changeset 307 1a73dddb1d05
child 394 1a79f9ee7f5c
equal deleted inserted replaced
306:f105cfcc2498 307:1a73dddb1d05
       
     1 #+LaTeX_CLASS: beamer
       
     2 #+LaTeX_CLASS_OPTIONS: [presentation]
       
     3 #+BEAMER_FRAME_LEVEL: 1
       
     4 
       
     5 #+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent}
       
     6 #+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra)
       
     7 #+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC
       
     8 
       
     9 #+LaTeX_CLASS: beamer
       
    10 #+LaTeX_CLASS_OPTIONS: [presentation]
       
    11 
       
    12 #+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl}
       
    13 #+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet}
       
    14 
       
    15 #+LaTeX_HEADER: \usepackage{listings}
       
    16 
       
    17 #+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries,
       
    18 #+LaTeX_HEADER:  commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen},
       
    19 #+LaTeX_HEADER:  showstringspaces=false, keywordstyle=\color{blue}\bfseries}
       
    20 
       
    21 #+TITLE: Matrices
       
    22 #+AUTHOR: FOSSEE
       
    23 #+EMAIL:     
       
    24 #+DATE:    
       
    25 
       
    26 #+DESCRIPTION: 
       
    27 #+KEYWORDS: 
       
    28 #+LANGUAGE:  en
       
    29 #+OPTIONS:   H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
       
    30 #+OPTIONS:   TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc
       
    31 
       
    32 * Outline
       
    33   - Creating Matrices
       
    34     - using direct data
       
    35     - converting a list
       
    36   - Matrix operations
       
    37   - Inverse of matrix
       
    38   - Determinant of matrix
       
    39   - Eigen values and Eigen vectors of matrices
       
    40   - Norm of matrix
       
    41   - Singular Value Decomposition of matrices
       
    42 
       
    43 * Creating a matrix
       
    44   - Creating a matrix using direct data
       
    45   : In []: m1 = matrix([1, 2, 3, 4])
       
    46   - Creating a matrix using lists
       
    47   : In []: l1 = [[1,2,3,4],[5,6,7,8]]
       
    48   : In []: m2 = matrix(l1)
       
    49   - A matrix is basically an array
       
    50   : In []: m3 = array([[5,6,7,8],[9,10,11,12]])
       
    51 
       
    52 * Matrix operations
       
    53   - Element-wise addition (both matrix should be of order ~mXn~)
       
    54     : In []: m3 + m2
       
    55   - Element-wise subtraction (both matrix should be of order ~mXn~)
       
    56     : In []: m3 - m2
       
    57 * Matrix Multiplication
       
    58   - Matrix Multiplication
       
    59     : In []: m3 * m2
       
    60     : Out []: ValueError: objects are not aligned
       
    61   - Element-wise multiplication using ~multiply()~
       
    62     : multiply(m3, m2)
       
    63 
       
    64 * Matrix Multiplication (cont'd)
       
    65   - Create two compatible matrices of order ~nXm~ and ~mXr~
       
    66     : In []: m1.shape
       
    67     - matrix m1 is of order ~1 X 4~
       
    68   - Creating another matrix of order ~4 X 2~
       
    69     : In []: m4 = matrix([[1,2],[3,4],[5,6],[7,8]])
       
    70   - Matrix multiplication
       
    71     : In []: m1 * m4
       
    72 * Recall from ~array~
       
    73   - The functions 
       
    74     - ~identity(n)~ - 
       
    75       creates an identity matrix of order ~nXn~
       
    76     - ~zeros((m,n))~ - 
       
    77       creates a matrix of order ~mXn~ with 0's
       
    78     - ~zeros_like(A)~ - 
       
    79       creates a matrix with 0's similar to the shape of matrix ~A~
       
    80     - ~ones((m,n))~
       
    81       creates a matrix of order ~mXn~ with 1's
       
    82     - ~ones_like(A)~
       
    83       creates a matrix with 1's similar to the shape of matrix ~A~
       
    84   Can also be used with matrices
       
    85 
       
    86 * More matrix operations
       
    87   Transpose of a matrix
       
    88   : In []: m4.T
       
    89 * Exercise 1 : Frobenius norm \& inverse
       
    90   Find out the Frobenius norm of inverse of a ~4 X 4~ matrix.
       
    91   : 
       
    92   The matrix is
       
    93   : m5 = matrix(arange(1,17).reshape(4,4))
       
    94   - Inverse of A, 
       
    95     - 
       
    96      #+begin_latex
       
    97        $A^{-1} = inv(A)$
       
    98      #+end_latex
       
    99   - Frobenius norm is defined as,
       
   100     - 
       
   101       #+begin_latex
       
   102         $||A||_F = [\sum_{i,j} abs(a_{i,j})^2]^{1/2}$
       
   103       #+end_latex
       
   104 
       
   105 * Exercise 2: Infinity norm
       
   106   Find the infinity norm of the matrix ~im5~
       
   107   : 
       
   108   - Infinity norm is defined as,
       
   109     #+begin_latex
       
   110        $max([\sum_{i} abs(a_{i})^2])$
       
   111     #+end_latex
       
   112 * ~norm()~ method
       
   113   - Frobenius norm
       
   114     : In []: norm(im5)
       
   115   - Infinity norm
       
   116     : In []: norm(im5, ord=inf)
       
   117 * Determinant
       
   118   Find out the determinant of the matrix m5
       
   119   : 
       
   120   - determinant can be found out using
       
   121     - ~det(A)~ - returns the determinant of matrix ~A~
       
   122 * eigen values \& eigen vectors
       
   123   Find out the eigen values and eigen vectors of the matrix ~m5~.
       
   124   : 
       
   125   - eigen values and vectors can be found out using
       
   126     : In []: eig(m5)
       
   127     returns a tuple of /eigen values/ and /eigen vectors/
       
   128   - /eigen values/ in tuple
       
   129     - ~In []: eig(m5)[0]~
       
   130   - /eigen vectors/ in tuple
       
   131     - ~In []: eig(m5)[1]~
       
   132   - Computing /eigen values/ using ~eigvals()~
       
   133     : In []: eigvals(m5)
       
   134 * Singular Value Decomposition (~svd~)
       
   135   #+begin_latex
       
   136     $M = U \Sigma V^*$
       
   137   #+end_latex
       
   138     - U, an ~mXm~ unitary matrix over K.
       
   139     - 
       
   140       #+begin_latex
       
   141         $\Sigma$
       
   142       #+end_latex
       
   143 	, an ~mXn~ diagonal matrix with non-negative real numbers on diagonal.
       
   144     - 
       
   145       #+begin_latex
       
   146         $V^*$
       
   147       #+end_latex
       
   148 	, an ~nXn~ unitary matrix over K, denotes the conjugate transpose of V.
       
   149   - SVD of matrix ~m5~ can be found out as,
       
   150     : In []: svd(m5)
       
   151 * Summary
       
   152   - Matrices
       
   153     - creating matrices
       
   154   - Matrix operations
       
   155   - Inverse (~inv()~)
       
   156   - Determinant (~det()~)
       
   157   - Norm (~norm()~)
       
   158   - Eigen values \& vectors (~eig(), eigvals()~)
       
   159   - Singular Value Decomposition (~svd()~)
       
   160 
       
   161 * Thank you!
       
   162 #+begin_latex
       
   163   \begin{block}{}
       
   164   \begin{center}
       
   165   This spoken tutorial has been produced by the
       
   166   \textcolor{blue}{FOSSEE} team, which is funded by the 
       
   167   \end{center}
       
   168   \begin{center}
       
   169     \textcolor{blue}{National Mission on Education through \\
       
   170       Information \& Communication Technology \\ 
       
   171       MHRD, Govt. of India}.
       
   172   \end{center}  
       
   173   \end{block}
       
   174 #+end_latex
       
   175 
       
   176