made changes to script, matrices, using array() instead of matrix() now.
authorAnoop Jacob Thomas<anoop@fossee.in>
Sun, 07 Nov 2010 16:20:02 +0530
changeset 394 1a79f9ee7f5c
parent 393 f99254fc7d70
child 395 72437215f3c5
made changes to script, matrices, using array() instead of matrix() now.
matrices/script.rst
matrices/slides.org
matrices/slides.tex
--- a/matrices/script.rst	Sun Nov 07 15:43:46 2010 +0530
+++ b/matrices/script.rst	Sun Nov 07 16:20:02 2010 +0530
@@ -51,7 +51,7 @@
 on arrays are valid on matrices also. A matrix may be created as,
 ::
 
-    m1 = matrix([1,2,3,4])
+    m1 = array([1,2,3,4])
 
 
 .. #[Puneeth: don't use ``matrix``. Use ``array``. The whole script will
@@ -70,10 +70,16 @@
 ::
 
     l1 = [[1,2,3,4],[5,6,7,8]]
-    m2 = matrix(l1)
+    m2 = array(l1)
+
+{{{ switch to next slide, exercise 1}}}
 
-Note that all matrix operations are done using arrays, so a matrix may
-also be created as
+Pause here and create a two dimensional matrix m3 of order 2 by 4 with
+elements 5, 6, 7, 8, 9, 10, 11, 12.
+
+{{{ switch to next slide, solution }}}
+
+m3 can be created as,
 ::
 
     m3 = array([[5,6,7,8],[9,10,11,12]])
@@ -100,17 +106,16 @@
 
     m3 * m2
 
-Note that in arrays ``array(A) star array(B)`` does element wise
-multiplication and not matrix multiplication, but unlike arrays, the
-operation ``matrix(A) star matrix(B)`` does matrix multiplication and
-not element wise multiplication. And in this case since the sizes are
-not compatible for multiplication it returned an error.
+Note that in arrays ``m3 * m2`` does element wise multiplication and not
+matrix multiplication,
 
-And element wise multiplication in matrices are done using the
-function ``multiply()``
+And matrix multiplication in matrices are done using the function ``dot()``
 ::
 
-    multiply(m3,m2)
+    dot(m3, m2)
+
+but due to size mismatch the multiplication could not be done and it
+returned an error,
 
 {{{ switch to next slide, Matrix multiplication (cont'd) }}}
 
@@ -126,11 +131,10 @@
 the order four by two,
 ::
 
-    m4 = matrix([[1,2],[3,4],[5,6],[7,8]])
-    m1 * m4
+    m4 = array([[1,2],[3,4],[5,6],[7,8]])
+    dot(m1, m4)
 
-thus unlike in array object ``star`` can be used for matrix multiplication
-in matrix object.
+thus the function ``dot()`` can be used for matrix multiplication.
 
 {{{ switch to next slide, recall from arrays }}}
 
@@ -158,7 +162,7 @@
 matrix, the matrix being,
 ::
 
-    m5 = matrix(arange(1,17).reshape(4,4))
+    m5 = arange(1,17).reshape(4,4)
     print m5
 
 The inverse of a matrix A, A raise to minus one is also called the
@@ -177,7 +181,7 @@
 ::
 
     sum = 0
-    for each in array(im5.flatten())[0]:
+    for each in im5.flatten():
         sum += each * each
     print sqrt(sum)
 
--- a/matrices/slides.org	Sun Nov 07 15:43:46 2010 +0530
+++ b/matrices/slides.org	Sun Nov 07 16:20:02 2010 +0530
@@ -42,11 +42,16 @@
 
 * Creating a matrix
   - Creating a matrix using direct data
-  : In []: m1 = matrix([1, 2, 3, 4])
+  : In []: m1 = array([1, 2, 3, 4])
   - Creating a matrix using lists
   : In []: l1 = [[1,2,3,4],[5,6,7,8]]
-  : In []: m2 = matrix(l1)
-  - A matrix is basically an array
+  : In []: m2 = array(l1)
+* Exercise 1
+  Create a (2, 4) matrix ~m3~
+  : m3 = [[5,  6,  7,  8],
+  :       [9, 10, 11, 12]]
+* Solution 1
+  - m3 can be created as,
   : In []: m3 = array([[5,6,7,8],[9,10,11,12]])
 
 * Matrix operations
@@ -55,20 +60,20 @@
   - Element-wise subtraction (both matrix should be of order ~mXn~)
     : In []: m3 - m2
 * Matrix Multiplication
-  - Matrix Multiplication
+  - Element-wise multiplication using ~m3 * m2~
     : In []: m3 * m2
+  - Matrix Multiplication using ~dot(m3, m2)~
+    : In []: dot(m3, m2)
     : Out []: ValueError: objects are not aligned
-  - Element-wise multiplication using ~multiply()~
-    : multiply(m3, m2)
 
 * Matrix Multiplication (cont'd)
   - Create two compatible matrices of order ~nXm~ and ~mXr~
     : In []: m1.shape
     - matrix m1 is of order ~1 X 4~
   - Creating another matrix of order ~4 X 2~
-    : In []: m4 = matrix([[1,2],[3,4],[5,6],[7,8]])
+    : In []: m4 = array([[1,2],[3,4],[5,6],[7,8]])
   - Matrix multiplication
-    : In []: m1 * m4
+    : In []: dot(m1, m4)
 * Recall from ~array~
   - The functions 
     - ~identity(n)~ - 
@@ -86,11 +91,11 @@
 * More matrix operations
   Transpose of a matrix
   : In []: m4.T
-* Exercise 1 : Frobenius norm \& inverse
+* Exercise 2 : Frobenius norm \& inverse
   Find out the Frobenius norm of inverse of a ~4 X 4~ matrix.
   : 
   The matrix is
-  : m5 = matrix(arange(1,17).reshape(4,4))
+  : m5 = arange(1,17).reshape(4,4)
   - Inverse of A, 
     - 
      #+begin_latex
@@ -102,7 +107,7 @@
         $||A||_F = [\sum_{i,j} abs(a_{i,j})^2]^{1/2}$
       #+end_latex
 
-* Exercise 2: Infinity norm
+* Exercise 3 : Infinity norm
   Find the infinity norm of the matrix ~im5~
   : 
   - Infinity norm is defined as,
--- a/matrices/slides.tex	Sun Nov 07 15:43:46 2010 +0530
+++ b/matrices/slides.tex	Sun Nov 07 16:20:02 2010 +0530
@@ -1,4 +1,4 @@
-% Created 2010-10-12 Tue 14:28
+% Created 2010-11-07 Sun 16:18
 \documentclass[presentation]{beamer}
 \usepackage[latin1]{inputenc}
 \usepackage[T1]{fontenc}
@@ -70,7 +70,7 @@
 \end{itemize}
 
 \begin{verbatim}
-   In []: m1 = matrix([1, 2, 3, 4])
+   In []: m1 = array([1, 2, 3, 4])
 \end{verbatim}
 
 \begin{itemize}
@@ -79,11 +79,25 @@
 
 \begin{verbatim}
    In []: l1 = [[1,2,3,4],[5,6,7,8]]
-   In []: m2 = matrix(l1)
+   In []: m2 = array(l1)
 \end{verbatim}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Exercise 1}
+\label{sec-3}
+
+  Create a (2, 4) matrix \texttt{m3}
+\begin{verbatim}
+   m3 = [[5,  6,  7,  8],
+         [9, 10, 11, 12]]
+\end{verbatim}
+\end{frame}
+\begin{frame}[fragile]
+\frametitle{Solution 1}
+\label{sec-4}
 
 \begin{itemize}
-\item A matrix is basically an array
+\item m3 can be created as,
 \end{itemize}
 
 \begin{verbatim}
@@ -92,7 +106,7 @@
 \end{frame}
 \begin{frame}[fragile]
 \frametitle{Matrix operations}
-\label{sec-3}
+\label{sec-5}
 
 \begin{itemize}
 \item Element-wise addition (both matrix should be of order \texttt{mXn})
@@ -109,25 +123,25 @@
 \end{frame}
 \begin{frame}[fragile]
 \frametitle{Matrix Multiplication}
-\label{sec-4}
+\label{sec-6}
 
 \begin{itemize}
-\item Matrix Multiplication
+\item Element-wise multiplication using \texttt{m3 * m2}
 \begin{verbatim}
      In []: m3 * m2
-     Out []: ValueError: objects are not aligned
 \end{verbatim}
 
-\item Element-wise multiplication using \texttt{multiply()}
+\item Matrix Multiplication using \texttt{dot(m3, m2)}
 \begin{verbatim}
-     multiply(m3, m2)
+     In []: dot(m3, m2)
+     Out []: ValueError: objects are not aligned
 \end{verbatim}
 
 \end{itemize}
 \end{frame}
 \begin{frame}[fragile]
 \frametitle{Matrix Multiplication (cont'd)}
-\label{sec-5}
+\label{sec-7}
 
 \begin{itemize}
 \item Create two compatible matrices of order \texttt{nXm} and \texttt{mXr}
@@ -142,19 +156,19 @@
 
 \item Creating another matrix of order \texttt{4 X 2}
 \begin{verbatim}
-     In []: m4 = matrix([[1,2],[3,4],[5,6],[7,8]])
+     In []: m4 = array([[1,2],[3,4],[5,6],[7,8]])
 \end{verbatim}
 
 \item Matrix multiplication
 \begin{verbatim}
-     In []: m1 * m4
+     In []: dot(m1, m4)
 \end{verbatim}
 
 \end{itemize}
 \end{frame}
 \begin{frame}
 \frametitle{Recall from \texttt{array}}
-\label{sec-6}
+\label{sec-8}
 
 \begin{itemize}
 \item The functions
@@ -178,7 +192,7 @@
 \end{frame}
 \begin{frame}[fragile]
 \frametitle{More matrix operations}
-\label{sec-7}
+\label{sec-9}
 
   Transpose of a matrix
 \begin{verbatim}
@@ -186,8 +200,8 @@
 \end{verbatim}
 \end{frame}
 \begin{frame}[fragile]
-\frametitle{Exercise 1 : Frobenius norm \& inverse}
-\label{sec-8}
+\frametitle{Exercise 2 : Frobenius norm \& inverse}
+\label{sec-10}
 
   Find out the Frobenius norm of inverse of a \texttt{4 X 4} matrix.
 \begin{verbatim}
@@ -196,7 +210,7 @@
 
   The matrix is
 \begin{verbatim}
-   m5 = matrix(arange(1,17).reshape(4,4))
+   m5 = arange(1,17).reshape(4,4)
 \end{verbatim}
 
 \begin{itemize}
@@ -215,8 +229,8 @@
 \end{itemize}
 \end{frame}
 \begin{frame}[fragile]
-\frametitle{Exercise 2: Infinity norm}
-\label{sec-9}
+\frametitle{Exercise 3 : Infinity norm}
+\label{sec-11}
 
   Find the infinity norm of the matrix \texttt{im5}
 \begin{verbatim}
@@ -230,7 +244,7 @@
 \end{frame}
 \begin{frame}[fragile]
 \frametitle{\texttt{norm()} method}
-\label{sec-10}
+\label{sec-12}
 
 \begin{itemize}
 \item Frobenius norm
@@ -247,7 +261,7 @@
 \end{frame}
 \begin{frame}[fragile]
 \frametitle{Determinant}
-\label{sec-11}
+\label{sec-13}
 
   Find out the determinant of the matrix m5
 \begin{verbatim}
@@ -265,7 +279,7 @@
 \end{frame}
 \begin{frame}[fragile]
 \frametitle{eigen values \& eigen vectors}
-\label{sec-12}
+\label{sec-14}
 
   Find out the eigen values and eigen vectors of the matrix \texttt{m5}.
 \begin{verbatim}
@@ -300,7 +314,7 @@
 \end{frame}
 \begin{frame}[fragile]
 \frametitle{Singular Value Decomposition (\texttt{svd})}
-\label{sec-13}
+\label{sec-15}
 
     $M = U \Sigma V^*$
 \begin{itemize}
@@ -318,7 +332,7 @@
 \end{frame}
 \begin{frame}
 \frametitle{Summary}
-\label{sec-14}
+\label{sec-16}
 
 \begin{itemize}
 \item Matrices
@@ -337,7 +351,7 @@
 \end{frame}
 \begin{frame}
 \frametitle{Thank you!}
-\label{sec-15}
+\label{sec-17}
 
   \begin{block}{}
   \begin{center}