Loads of changes done.
authorSantosh G. Vattam <vattam.santosh@gmail.com>
Sat, 31 Oct 2009 01:20:28 +0530
changeset 274 34f71bdd0263
parent 259 bb77a470e00a
child 275 71e50184d482
Loads of changes done.
day1/session2.tex
day1/session4.tex
--- a/day1/session2.tex	Thu Oct 29 00:39:33 2009 +0530
+++ b/day1/session2.tex	Sat Oct 31 01:20:28 2009 +0530
@@ -1,4 +1,4 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %Tutorial slides on Python.
 %
 % Author: FOSSEE
@@ -124,12 +124,9 @@
 \end{frame}
 
 \begin{frame}
-\frametitle{Why we didn't close the IPython??}
-\begin{itemize}
-  \item IPython provides a convenient feature
-  \item To go back, edit, and re-run commands
-  \item But when you close, this is lost
-\end{itemize}
+\frametitle{Why we didn't close IPython?}
+  IPython provides a convenient feature to go back, edit, and re-run commands.\\
+  \alert{But when you close, all this is lost.}
 \end{frame}
 
 \begin{frame}
@@ -148,7 +145,7 @@
 \begin{frame}[fragile]
 \frametitle{Python Scripts}
 \begin{itemize}
-\item Put all commands used in review problem into a file. 
+\item Put commands used in review problem into file. 
 \item use hist command of IPython.
 \end{itemize}
 \begin{lstlisting}
@@ -161,17 +158,18 @@
 \frametitle{Python Scripts\ldots}
   \begin{itemize}
     \item Open a new file in an \alert{editor}
-    \item Copy and paste required lines from the output of \typ{\%hist -n}
+    \item Copy and paste from the output of \typ{\%hist -n}
     \item Save the file as \typ{sine_plot.py}
   \end{itemize}
   \begin{itemize}
-  \item run the file in IPython using \typ{\%run sine_plot.py}\\
+  \item run the file in IPython using \typ{\%run -i sine_plot.py}\\
   \end{itemize}
 \end{frame}
 
 \begin{frame}[fragile]
 \frametitle{Why would I plot f(x)?}
 How often do we plot analytical functions?\\We plot experimental data more.
+\begin{small}
 \begin{lstlisting}
 In []: x = [0, 1, 2, 3]
 
@@ -179,14 +177,21 @@
 
 In []: plot(x, y)
 Out[]: [<matplotlib.lines.Line2D object at 0xa73aa8c>]
+
+In []: xlabel('X')
+Out[]: <matplotlib.text.Text object at 0x986e9ac>
+
+In []: ylabel('Y')
+Out[]: <matplotlib.text.Text object at 0x98746ec>
 \end{lstlisting}
+\end{small}
 \end{frame}
 
 \begin{frame}[fragile]
 \begin{figure}
 \includegraphics[width=3.5in]{data/straightline.png}
 \end{figure}
-\alert{Is this what you have??}
+\alert{Is this what you have?}
 \end{frame}
 
 \begin{frame}[fragile]
@@ -197,11 +202,11 @@
 \begin{lstlisting}
   In []: clf()
 
-  In []: plot(L, TSq, 'o')
+  In []: plot(x, y, 'o')
   Out[]: [<matplotlib.lines.Line2D object at 0xac17e0c>]
 
   In []: clf()
-  In []: plot(L, TSq, '.')
+  In []: plot(x, y, '.')
   Out[]: [<matplotlib.lines.Line2D object at 0xac17e0c>]
 \end{lstlisting}
 \end{frame}
@@ -216,8 +221,8 @@
 \begin{frame}[fragile]
 \frametitle{Additional Plotting Attributes}
 \begin{itemize}
-  \item \kwrd{'o'} - Dots
-  \item \kwrd{'.'} - Smaller Dots
+  \item \kwrd{'o'} - Filled circles
+  \item \kwrd{'.'} - Small Dots
   \item \kwrd{'-'} - Lines
   \item \kwrd{'- -'} - Dashed lines
 \end{itemize}
@@ -226,14 +231,14 @@
 \section{Lists}
 \begin{frame}[fragile]
   \frametitle{How to create the data?}
-What were \typ{x} and \typ{y}??\\
+What were \typ{x} and \typ{y}?\\
 \begin{center}
 \alert{\typ{lists!!}}
 \end{center}
 \begin{lstlisting}
 In []: mtlist = [] #Empty List
 
-In []: lst = [1,2,3,4,5] 
+In []: lst = [ 1, 2, 3, 4, 5] 
 \end{lstlisting}
 \end{frame}
 
@@ -248,9 +253,8 @@
 \begin{frame}[fragile]
   \frametitle{List: Slicing}
   \begin{block}{Remember\ldots}
-	\kwrd{In []: lst = [1,2,3,4,5]}
+	\kwrd{In []: lst = [ 1, 2, 3, 4, 5]}
   \end{block}
-\alert{\typ{list[initial:final:step]}}
 \begin{lstlisting}
 In []: lst[1:3]  # A slice.
 Out[]: [2, 3]
@@ -258,12 +262,13 @@
 In []: lst[1:-1]
 Out[]: [2, 3]
 \end{lstlisting}
+\alert{\typ{list[initial:final]}}
 \end{frame}
 
 \begin{frame}[fragile]
 \frametitle{List operations}
 \begin{lstlisting}
-In []: anthrlst = [6,7,8,9]
+In []: anthrlst = [ 6, 7, 8, 9]
 In []: lnglst = lst + anthrlst
 
 In []: lnglst
@@ -271,7 +276,7 @@
 
 In []: lst.append(6)
 In []: lst
-Out[]: [1, 2, 3, 4, 5, 6]
+Out[]: [ 1, 2, 3, 4, 5, 6]
 \end{lstlisting}
 %\inctime{10}
 \end{frame}
@@ -332,7 +337,7 @@
 In []: plot(L, TSq)
 Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>]
 \end{lstlisting}
-This gives the list \kwrd{TSq} which is the list of squares of T values.
+This gives \kwrd{TSq} which is the list of squares of T values.
 \end{frame}
 
 \begin{frame}[fragile]
@@ -342,31 +347,11 @@
 \end{frame}
 
 \begin{frame}[fragile]
-\frametitle{More of \texttt{for}}
-\begin{itemize}
-\item Used to iterate over lists
-\item Let us look at another example.
-\end{itemize}
+\frametitle{What about larger data sets?}
+\alert{Data is usually present in a file!} \\
+Lets look at the \typ{pendulum.txt} file.
 \begin{lstlisting}
-In []: lst = [1,2,3,4,5,6]
-In []: for num in lst:
- ....:     print num, num*num
- ....:    
-1 1
-2 4
-3 9
-4 16
-5 25
-6 36
-\end{lstlisting}
-\end{frame}
-
-\begin{frame}[fragile]
-\frametitle{What about larger data sets??}
-\alert{Data is usually present in a file!} \\
-Lets look at the pendulum.txt file.
-\begin{lstlisting}
-$cat data/pendulum.txt 
+$ cat pendulum.txt 
 1.0000e-01 6.9004e-01
 1.1000e-01 6.9497e-01
 1.2000e-01 7.4252e-01
@@ -378,18 +363,16 @@
 \end{frame}
 
 \begin{frame}[fragile]
-\frametitle{Reading pendulum.txt}
+\frametitle{Reading \typ{pendulum.txt}}
 \begin{itemize}
-  \item We now wish to repeat the plot using the values from a file
-  \item Given a file containing L vs. T values 
-  \item Column1 - L; Column2 - T  
-  \item Read the file
-  \item Plot points for L vs. $T^2$ 
+  \item Let us generate a plot from the data file
+  \item File contains L vs. T values 
+  \item L - Column1; T - Column2
 \end{itemize}
 \end{frame}
 
 \begin{frame}[fragile]
-\frametitle{Reading pendulum.txt}
+\frametitle{Reading \typ{pendulum.txt}}
 \begin{lstlisting}
 In []: L = []
 In []: T = []
@@ -400,12 +383,12 @@
 \end{lstlisting}
 \begin{itemize}
 \item We now have two lists L and T
-\item Now, Repeat previous steps for plotting
+\item Now, repeat previous steps for plotting
 \end{itemize}
 \end{frame}
 
 \begin{frame}[fragile]
-\frametitle{Plotting from pendulum.txt}
+\frametitle{Plotting from \typ{pendulum.txt}}
 \begin{lstlisting}
 In []: TSq = []
 
@@ -426,9 +409,9 @@
   \frametitle{Reading files \ldots}
 \typ{In []: for line in open('pendulum.txt'):}
 \begin{itemize}
-\item opening file `pendulum.txt'
-\item iterating through the file by reading each line into variable \typ{line}
-\item \typ{line} is a \kwrd{string} variable
+\item opening file `\typ{pendulum.txt}'
+\item reading the file line by line
+\item \typ{line} is a \kwrd{string}
 \end{itemize}
 \end{frame}
 
@@ -447,9 +430,9 @@
 \begin{frame}[fragile]
 \frametitle{Strings and \typ{split()}}
   \begin{lstlisting}
-In []: line = 'hello world'
+In []: greet = 'hello world'
 
-In []: line.split()
+In []: greet.split()
 Out[]: ['hello', 'world']
   \end{lstlisting}
 This is what happens with \typ{line}
@@ -476,13 +459,42 @@
   \end{lstlisting}
 \end{frame}
 
+\begin{frame}[fragile]
+\frametitle{Let's review the code}
+\begin{small}
+\begin{lstlisting}
+In []: L = []
+In []: T = []
+In []: for line in open('pendulum.txt'):
+  ....     points = line.split()
+  ....     L.append(float(points[0]))
+  ....     T.append(float(points[1]))
+
+In []: TSq = []
+
+In []: for t in T:
+ ....:     TSq.append(t*t)
+
+In []: plot(L, TSq, '.')
+\end{lstlisting}
+\end{small}
+\end{frame}
+
+\begin{frame}[fragile]
+\begin{figure}
+\includegraphics[width=3.5in]{data/L-Tsq.png}
+\end{figure}
+\end{frame}
+
 \section {Summary}
-\begin{frame}
-\frametitle{Summary}
-So what did we learn in this session??
+\begin{frame}[fragile]
+\frametitle{What did we learn?}
 \begin{itemize}
-  \item Creating and running Python scripts
-  \item Plotting points and Plotting attributes
+  \item \kwrd{\%hist -n}
+  \item Python scripts
+  \item \kwrd{\%run -i}
+  \item Plotting points
+  \item Plot attributes
   \item Lists
   \item \kwrd{for}
   \item Reading files
--- a/day1/session4.tex	Thu Oct 29 00:39:33 2009 +0530
+++ b/day1/session4.tex	Sat Oct 31 01:20:28 2009 +0530
@@ -128,24 +128,24 @@
 
 \begin{frame}
 \frametitle{Matrices: Introduction}
-We looked at the Van der Monde matrix in the previous session,\\ 
-let us now look at matrices in a little more detail.
+Let us now look at matrices in detail.\\
+\alert{All matrix operations are done using \kwrd{arrays}}
 \end{frame}
 
 \subsection{Initializing}
 \begin{frame}[fragile]
 \frametitle{Matrices: Initializing}
 \begin{lstlisting}
-In []: A = matrix([[ 1,  1,  2, -1],
-                   [ 2,  5, -1, -9],
-                   [ 2,  1, -1,  3],
-                   [ 1, -3,  2,  7]])
+In []: A = array([[ 1,  1,  2, -1],
+                  [ 2,  5, -1, -9],
+                  [ 2,  1, -1,  3],
+                  [ 1, -3,  2,  7]])
 In []: A
 Out[]: 
-matrix([[ 1,  1,  2, -1],
-        [ 2,  5, -1, -9],
-        [ 2,  1, -1,  3],
-        [ 1, -3,  2,  7]])
+array([[ 1,  1,  2, -1],
+       [ 2,  5, -1, -9],
+       [ 2,  1, -1,  3],
+       [ 1, -3,  2,  7]])
 \end{lstlisting}
 \end{frame}
 
@@ -154,19 +154,19 @@
 \begin{frame}[fragile]
 \frametitle{Transpose of a Matrix}
 \begin{lstlisting}
-In []: linalg.transpose(A)
+In []: A.T
 Out[]:
-matrix([[ 1,  2,  2,  1],
-        [ 1,  5,  1, -3],
-        [ 2, -1, -1,  2],
-        [-1, -9,  3,  7]])
+array([[ 1,  2,  2,  1],
+       [ 1,  5,  1, -3],
+       [ 2, -1, -1,  2],
+       [-1, -9,  3,  7]])
 \end{lstlisting}
 \end{frame}
 
 \begin{frame}[fragile]
   \frametitle{Sum of all elements}
   \begin{lstlisting}
-In []: linalg.sum(A)
+In []: sum(A)
 Out[]: 12
   \end{lstlisting}
 \end{frame}
@@ -174,41 +174,56 @@
 \begin{frame}[fragile]
   \frametitle{Matrix Addition}
   \begin{lstlisting}
-In []: B = matrix([[3,2,-1,5],
-                   [2,-2,4,9],
-                   [-1,0.5,-1,-7],
-                   [9,-5,7,3]])
-In []: linalg.add(A,B)
+In []: B = array([[3,2,-1,5],
+                  [2,-2,4,9],
+                  [-1,0.5,-1,-7],
+                  [9,-5,7,3]])
+In []: A + B
 Out[]: 
-matrix([[  4. ,   3. ,   1. ,   4. ],
-        [  4. ,   3. ,   3. ,   0. ],
-        [  1. ,   1.5,  -2. ,  -4. ],
-        [ 10. ,  -8. ,   9. ,  10. ]])
+array([[  4. ,   3. ,   1. ,   4. ],
+       [  4. ,   3. ,   3. ,   0. ],
+       [  1. ,   1.5,  -2. ,  -4. ],
+       [ 10. ,  -8. ,   9. ,  10. ]])
   \end{lstlisting}
 \end{frame}
 
 \begin{frame}[fragile]
+\frametitle{Elementwise Multiplication}
+\begin{lstlisting}
+In []: A*B
+Out[]: 
+array([[  3. ,   2. ,  -2. ,  -5. ],
+       [  4. , -10. ,  -4. , -81. ],
+       [ -2. ,   0.5,   1. , -21. ],
+       [  9. ,  15. ,  14. ,  21. ]])
+
+\end{lstlisting}
+\end{frame}
+
+\begin{frame}[fragile]
 \frametitle{Matrix Multiplication}
 \begin{lstlisting}
-In []: linalg.multiply(A, B)
+In []: dot(A,B)
 Out[]: 
-matrix([[  3. ,   2. ,  -2. ,  -5. ],
-        [  4. , -10. ,  -4. , -81. ],
-        [ -2. ,   0.5,   1. , -21. ],
-        [  9. ,  15. ,  14. ,  21. ]])
+array([[ -6. ,   6. ,  -6. ,  -3. ],
+       [-64. ,  38.5, -44. ,  35. ],
+       [ 36. , -13.5,  24. ,  35. ],
+       [ 58. , -26. ,  34. , -15. ]])
 \end{lstlisting}
 \end{frame}
 
 \begin{frame}[fragile]
 \frametitle{Inverse of a Matrix}
+\begin{lstlisting}
+In []: inv(A)
+\end{lstlisting}
 \begin{small}
 \begin{lstlisting}
-In []: linalg.inv(A)
 Out[]: 
-matrix([[-0.5 ,  0.55, -0.15,  0.7 ],
-        [ 0.75, -0.5 ,  0.5 , -0.75],
-        [ 0.5 , -0.15, -0.05, -0.1 ],
-        [ 0.25, -0.25,  0.25, -0.25]])
+array([[-0.5 ,  0.55, -0.15,  0.7 ],
+       [ 0.75, -0.5 ,  0.5 , -0.75],
+       [ 0.5 , -0.15, -0.05, -0.1 ],
+       [ 0.25, -0.25,  0.25, -0.25]])
 \end{lstlisting}
 \end{small}
 \end{frame}
@@ -217,24 +232,24 @@
 \frametitle{Determinant}
 \begin{lstlisting}
 In []: det(A)
-Out[66]: 80.0
+Out[]: 80.0
 \end{lstlisting}
 \end{frame}
 
 \begin{frame}[fragile]
-\frametitle{Eigen Values and Eigen Matrix}
+\frametitle{Eigenvalues and Eigen Vectors}
 \begin{small}
 \begin{lstlisting}
-In []: E = matrix([[3,2,4],[2,0,2],[4,2,3]])
+In []: E = array([[3,2,4],[2,0,2],[4,2,3]])
 
-In []: linalg.eig(E)
+In []: eig(E)
 Out[]: 
 (array([-1.,  8., -1.]),
- matrix([[-0.74535599,  0.66666667, -0.1931126 ],
+ array([[-0.74535599,  0.66666667, -0.1931126 ],
         [ 0.2981424 ,  0.33333333, -0.78664085],
         [ 0.59628479,  0.66666667,  0.58643303]]))
 
-In []: linalg.eigvals(E)
+In []: eigvals(E)
 Out[]: array([-1.,  8., -1.])
 \end{lstlisting}
 \end{small}
@@ -243,23 +258,23 @@
 \begin{frame}[fragile]
 \frametitle{Computing Norms}
 \begin{lstlisting}
-In []: linalg.norm(E)
+In []: norm(E)
 Out[]: 8.1240384046359608
 \end{lstlisting}
 \end{frame}
 
 \begin{frame}[fragile]
-  \frametitle{Single Value Decomposition}
+  \frametitle{Singular Value Decomposition}
   \begin{small}
   \begin{lstlisting}
-In [76]: linalg.svd(E)
-Out[76]: 
-(matrix(
+In []: svd(E)
+Out[]: 
+(array(
 [[ -6.66666667e-01,  -1.23702565e-16,   7.45355992e-01],
  [ -3.33333333e-01,  -8.94427191e-01,  -2.98142397e-01],
  [ -6.66666667e-01,   4.47213595e-01,  -5.96284794e-01]]),
  array([ 8.,  1.,  1.]),
- matrix([[-0.66666667, -0.33333333, -0.66666667],
+ array([[-0.66666667, -0.33333333, -0.66666667],
         [-0.        ,  0.89442719, -0.4472136 ],
         [-0.74535599,  0.2981424 ,  0.59628479]]))
   \end{lstlisting}
@@ -289,12 +304,12 @@
 \frametitle{Solving using Matrices}
 Let us now look at how to solve this using \kwrd{matrices}
   \begin{lstlisting}
-    In []: A = matrix([[3,2,-1],
-                       [2,-2,4],
-                       [-1, 0.5, -1]])
-    In []: b = matrix([[1], [-2], [0]])
-    In []: x = linalg.solve(A, b)
-    In []: Ax = dot(A, x)
+    In []: A = array([[3,2,-1],
+                      [2,-2,4],                   
+                      [-1, 0.5, -1]])
+    In []: b = array([[1], [-2], [0]])
+    In []: x = solve(A, b)
+    In []: Ax = dot(A,x)
   \end{lstlisting}
 \end{frame}
 
@@ -314,9 +329,9 @@
 \begin{lstlisting}
 In []: Ax
 Out[]: 
-matrix([[  1.00000000e+00],
-        [ -2.00000000e+00],
-        [  2.22044605e-16]])
+array([[  1.00000000e+00],
+       [ -2.00000000e+00],
+       [  2.22044605e-16]])
 \end{lstlisting}
 \begin{block}{}
 The last term in the matrix is actually \alert{0}!\\
@@ -332,7 +347,74 @@
 \subsection{Exercises}
 
 \begin{frame}[fragile]
-\frametitle{Problem Set 4: Problem 4.1}
+\frametitle{Problem 1}
+Given the matrix:\\
+\begin{center}
+\begin{bmatrix}
+-2 & 2 & 3\\
+ 2 & 1 & 6\\
+-1 &-2 & 0\\
+\end{bmatrix}
+\end{center}
+Find:
+\begin{itemize}
+  \item[i] Transpose
+  \item[ii]Inverse
+  \item[iii]Determinant
+  \item[iv] Eigenvalues and Eigen vectors
+  \item[v] Singular Value decomposition
+\end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Problem 2}
+Given 
+\begin{center}
+A = 
+\begin{bmatrix}
+-3 & 1 & 5 \\
+1 & 0 & -2 \\
+5 & -2 & 4 \\
+\end{bmatrix}
+, B = 
+\begin{bmatrix}
+0 & 9 & -12 \\
+-9 & 0 & 20 \\
+12 & -20 & 0 \\
+\end{bmatrix}
+\end{center}
+Find:
+\begin{itemize}
+  \item[i] Sum of A and B
+  \item[ii]Elementwise Product of A and B
+  \item[iii] Matrix product of A and B
+\end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Solution}
+Sum: 
+\begin{bmatrix}
+-3 & 10 & 7 \\
+-8 & 0 & 18 \\
+17 & -22 & 4 \\
+\end{bmatrix}
+,\\ Elementwise Product:
+\begin{bmatrix}
+0 & 9 & -60 \\
+-9 & 0 & -40 \\
+60 & 40 & 0 \\
+\end{bmatrix}
+,\\ Matrix product:
+\begin{bmatrix}
+51 & -127 & 56 \\
+-24 & 49 & -12 \\
+66 & -35 & -100 \\
+\end{bmatrix}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Problem 3}
 Solve the set of equations:
 \begin{align*}
   x + y + 2z -w & = 3\\
@@ -345,26 +427,18 @@
 
 \begin{frame}[fragile]
 \frametitle{Solution}
-Solution:
-\begin{lstlisting}
+Use \kwrd{solve()}
 \begin{align*}
   x & = -5\\
   y & = 2\\
   z & = 3\\
   w & = 0\\
 \end{align*}
-\end{lstlisting}
-\end{frame}
-
-\begin{frame}[fragile]
-\frametitle{Problem 4.2}
-
 \end{frame}
 
 \section{Summary}
 \begin{frame}
-  \frametitle{Summary}
-So what did we learn??
+  \frametitle{What did we learn??}
   \begin{itemize}
   \item Matrices
     \begin{itemize}
@@ -373,9 +447,9 @@
       \item Multiplication
       \item Inverse of a matrix
       \item Determinant
-      \item Eigen values and Eigen matrix
+      \item Eigenvalues and Eigen vector
       \item Norms
-      \item Single Value Decomposition
+      \item Singular Value Decomposition
     \end{itemize}
   \item Solving linear equations
   \end{itemize}