author | bhanu |
Thu, 11 Nov 2010 02:16:07 +0530 | |
changeset 477 | 0406115dccd1 |
parent 394 | 1a79f9ee7f5c |
permissions | -rw-r--r-- |
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
1 |
% Created 2010-11-07 Sun 16:18 |
307 | 2 |
\documentclass[presentation]{beamer} |
3 |
\usepackage[latin1]{inputenc} |
|
4 |
\usepackage[T1]{fontenc} |
|
5 |
\usepackage{fixltx2e} |
|
6 |
\usepackage{graphicx} |
|
7 |
\usepackage{longtable} |
|
8 |
\usepackage{float} |
|
9 |
\usepackage{wrapfig} |
|
10 |
\usepackage{soul} |
|
11 |
\usepackage{t1enc} |
|
12 |
\usepackage{textcomp} |
|
13 |
\usepackage{marvosym} |
|
14 |
\usepackage{wasysym} |
|
15 |
\usepackage{latexsym} |
|
16 |
\usepackage{amssymb} |
|
17 |
\usepackage{hyperref} |
|
18 |
\tolerance=1000 |
|
19 |
\usepackage[english]{babel} \usepackage{ae,aecompl} |
|
20 |
\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} |
|
21 |
\usepackage{listings} |
|
22 |
\lstset{language=Python, basicstyle=\ttfamily\bfseries, |
|
23 |
commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, |
|
24 |
showstringspaces=false, keywordstyle=\color{blue}\bfseries} |
|
25 |
\providecommand{\alert}[1]{\textbf{#1}} |
|
26 |
||
27 |
\title{Matrices} |
|
28 |
\author{FOSSEE} |
|
29 |
\date{} |
|
30 |
||
31 |
\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} |
|
32 |
\begin{document} |
|
33 |
||
34 |
\maketitle |
|
35 |
||
36 |
||
37 |
||
38 |
||
39 |
||
40 |
||
41 |
||
42 |
||
43 |
||
44 |
\begin{frame} |
|
45 |
\frametitle{Outline} |
|
46 |
\label{sec-1} |
|
47 |
||
48 |
\begin{itemize} |
|
49 |
\item Creating Matrices |
|
50 |
||
51 |
\begin{itemize} |
|
52 |
\item using direct data |
|
53 |
\item converting a list |
|
54 |
\end{itemize} |
|
55 |
||
56 |
\item Matrix operations |
|
57 |
\item Inverse of matrix |
|
58 |
\item Determinant of matrix |
|
59 |
\item Eigen values and Eigen vectors of matrices |
|
60 |
\item Norm of matrix |
|
61 |
\item Singular Value Decomposition of matrices |
|
62 |
\end{itemize} |
|
63 |
\end{frame} |
|
64 |
\begin{frame}[fragile] |
|
65 |
\frametitle{Creating a matrix} |
|
66 |
\label{sec-2} |
|
67 |
||
68 |
\begin{itemize} |
|
69 |
\item Creating a matrix using direct data |
|
70 |
\end{itemize} |
|
71 |
||
72 |
\begin{verbatim} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
73 |
In []: m1 = array([1, 2, 3, 4]) |
307 | 74 |
\end{verbatim} |
75 |
||
76 |
\begin{itemize} |
|
77 |
\item Creating a matrix using lists |
|
78 |
\end{itemize} |
|
79 |
||
80 |
\begin{verbatim} |
|
81 |
In []: l1 = [[1,2,3,4],[5,6,7,8]] |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
82 |
In []: m2 = array(l1) |
307 | 83 |
\end{verbatim} |
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
84 |
\end{frame} |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
85 |
\begin{frame}[fragile] |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
86 |
\frametitle{Exercise 1} |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
87 |
\label{sec-3} |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
88 |
|
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
89 |
Create a (2, 4) matrix \texttt{m3} |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
90 |
\begin{verbatim} |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
91 |
m3 = [[5, 6, 7, 8], |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
92 |
[9, 10, 11, 12]] |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
93 |
\end{verbatim} |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
94 |
\end{frame} |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
95 |
\begin{frame}[fragile] |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
96 |
\frametitle{Solution 1} |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
97 |
\label{sec-4} |
307 | 98 |
|
99 |
\begin{itemize} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
100 |
\item m3 can be created as, |
307 | 101 |
\end{itemize} |
102 |
||
103 |
\begin{verbatim} |
|
104 |
In []: m3 = array([[5,6,7,8],[9,10,11,12]]) |
|
105 |
\end{verbatim} |
|
106 |
\end{frame} |
|
107 |
\begin{frame}[fragile] |
|
108 |
\frametitle{Matrix operations} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
109 |
\label{sec-5} |
307 | 110 |
|
111 |
\begin{itemize} |
|
112 |
\item Element-wise addition (both matrix should be of order \texttt{mXn}) |
|
113 |
\begin{verbatim} |
|
114 |
In []: m3 + m2 |
|
115 |
\end{verbatim} |
|
116 |
||
117 |
\item Element-wise subtraction (both matrix should be of order \texttt{mXn}) |
|
118 |
\begin{verbatim} |
|
119 |
In []: m3 - m2 |
|
120 |
\end{verbatim} |
|
121 |
||
122 |
\end{itemize} |
|
123 |
\end{frame} |
|
124 |
\begin{frame}[fragile] |
|
125 |
\frametitle{Matrix Multiplication} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
126 |
\label{sec-6} |
307 | 127 |
|
128 |
\begin{itemize} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
129 |
\item Element-wise multiplication using \texttt{m3 * m2} |
307 | 130 |
\begin{verbatim} |
131 |
In []: m3 * m2 |
|
132 |
\end{verbatim} |
|
133 |
||
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
134 |
\item Matrix Multiplication using \texttt{dot(m3, m2)} |
307 | 135 |
\begin{verbatim} |
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
136 |
In []: dot(m3, m2) |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
137 |
Out []: ValueError: objects are not aligned |
307 | 138 |
\end{verbatim} |
139 |
||
140 |
\end{itemize} |
|
141 |
\end{frame} |
|
142 |
\begin{frame}[fragile] |
|
143 |
\frametitle{Matrix Multiplication (cont'd)} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
144 |
\label{sec-7} |
307 | 145 |
|
146 |
\begin{itemize} |
|
147 |
\item Create two compatible matrices of order \texttt{nXm} and \texttt{mXr} |
|
148 |
\begin{verbatim} |
|
149 |
In []: m1.shape |
|
150 |
\end{verbatim} |
|
151 |
||
152 |
||
153 |
\begin{itemize} |
|
154 |
\item matrix m1 is of order \texttt{1 X 4} |
|
155 |
\end{itemize} |
|
156 |
||
157 |
\item Creating another matrix of order \texttt{4 X 2} |
|
158 |
\begin{verbatim} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
159 |
In []: m4 = array([[1,2],[3,4],[5,6],[7,8]]) |
307 | 160 |
\end{verbatim} |
161 |
||
162 |
\item Matrix multiplication |
|
163 |
\begin{verbatim} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
164 |
In []: dot(m1, m4) |
307 | 165 |
\end{verbatim} |
166 |
||
167 |
\end{itemize} |
|
168 |
\end{frame} |
|
169 |
\begin{frame} |
|
170 |
\frametitle{Recall from \texttt{array}} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
171 |
\label{sec-8} |
307 | 172 |
|
173 |
\begin{itemize} |
|
174 |
\item The functions |
|
175 |
||
176 |
\begin{itemize} |
|
177 |
\item \texttt{identity(n)} - |
|
178 |
creates an identity matrix of order \texttt{nXn} |
|
179 |
\item \texttt{zeros((m,n))} - |
|
180 |
creates a matrix of order \texttt{mXn} with 0's |
|
181 |
\item \texttt{zeros\_like(A)} - |
|
182 |
creates a matrix with 0's similar to the shape of matrix \texttt{A} |
|
183 |
\item \texttt{ones((m,n))} |
|
184 |
creates a matrix of order \texttt{mXn} with 1's |
|
185 |
\item \texttt{ones\_like(A)} |
|
186 |
creates a matrix with 1's similar to the shape of matrix \texttt{A} |
|
187 |
\end{itemize} |
|
188 |
||
189 |
\end{itemize} |
|
190 |
||
191 |
Can also be used with matrices |
|
192 |
\end{frame} |
|
193 |
\begin{frame}[fragile] |
|
194 |
\frametitle{More matrix operations} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
195 |
\label{sec-9} |
307 | 196 |
|
197 |
Transpose of a matrix |
|
198 |
\begin{verbatim} |
|
199 |
In []: m4.T |
|
200 |
\end{verbatim} |
|
201 |
\end{frame} |
|
202 |
\begin{frame}[fragile] |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
203 |
\frametitle{Exercise 2 : Frobenius norm \& inverse} |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
204 |
\label{sec-10} |
307 | 205 |
|
206 |
Find out the Frobenius norm of inverse of a \texttt{4 X 4} matrix. |
|
207 |
\begin{verbatim} |
|
208 |
||
209 |
\end{verbatim} |
|
210 |
||
211 |
The matrix is |
|
212 |
\begin{verbatim} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
213 |
m5 = arange(1,17).reshape(4,4) |
307 | 214 |
\end{verbatim} |
215 |
||
216 |
\begin{itemize} |
|
217 |
\item Inverse of A, |
|
218 |
||
219 |
\begin{itemize} |
|
220 |
\item $A^{-1} = inv(A)$ |
|
221 |
\end{itemize} |
|
222 |
||
223 |
\item Frobenius norm is defined as, |
|
224 |
||
225 |
\begin{itemize} |
|
226 |
\item $||A||_F = [\sum_{i,j} abs(a_{i,j})^2]^{1/2}$ |
|
227 |
\end{itemize} |
|
228 |
||
229 |
\end{itemize} |
|
230 |
\end{frame} |
|
231 |
\begin{frame}[fragile] |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
232 |
\frametitle{Exercise 3 : Infinity norm} |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
233 |
\label{sec-11} |
307 | 234 |
|
235 |
Find the infinity norm of the matrix \texttt{im5} |
|
236 |
\begin{verbatim} |
|
237 |
||
238 |
\end{verbatim} |
|
239 |
||
240 |
\begin{itemize} |
|
241 |
\item Infinity norm is defined as, |
|
242 |
$max([\sum_{i} abs(a_{i})^2])$ |
|
243 |
\end{itemize} |
|
244 |
\end{frame} |
|
245 |
\begin{frame}[fragile] |
|
246 |
\frametitle{\texttt{norm()} method} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
247 |
\label{sec-12} |
307 | 248 |
|
249 |
\begin{itemize} |
|
250 |
\item Frobenius norm |
|
251 |
\begin{verbatim} |
|
252 |
In []: norm(im5) |
|
253 |
\end{verbatim} |
|
254 |
||
255 |
\item Infinity norm |
|
256 |
\begin{verbatim} |
|
257 |
In []: norm(im5, ord=inf) |
|
258 |
\end{verbatim} |
|
259 |
||
260 |
\end{itemize} |
|
261 |
\end{frame} |
|
262 |
\begin{frame}[fragile] |
|
263 |
\frametitle{Determinant} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
264 |
\label{sec-13} |
307 | 265 |
|
266 |
Find out the determinant of the matrix m5 |
|
267 |
\begin{verbatim} |
|
268 |
||
269 |
\end{verbatim} |
|
270 |
||
271 |
\begin{itemize} |
|
272 |
\item determinant can be found out using |
|
273 |
||
274 |
\begin{itemize} |
|
275 |
\item \texttt{det(A)} - returns the determinant of matrix \texttt{A} |
|
276 |
\end{itemize} |
|
277 |
||
278 |
\end{itemize} |
|
279 |
\end{frame} |
|
280 |
\begin{frame}[fragile] |
|
281 |
\frametitle{eigen values \& eigen vectors} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
282 |
\label{sec-14} |
307 | 283 |
|
284 |
Find out the eigen values and eigen vectors of the matrix \texttt{m5}. |
|
285 |
\begin{verbatim} |
|
286 |
||
287 |
\end{verbatim} |
|
288 |
||
289 |
\begin{itemize} |
|
290 |
\item eigen values and vectors can be found out using |
|
291 |
\begin{verbatim} |
|
292 |
In []: eig(m5) |
|
293 |
\end{verbatim} |
|
294 |
||
295 |
returns a tuple of \emph{eigen values} and \emph{eigen vectors} |
|
296 |
\item \emph{eigen values} in tuple |
|
297 |
||
298 |
\begin{itemize} |
|
299 |
\item \texttt{In []: eig(m5)[0]} |
|
300 |
\end{itemize} |
|
301 |
||
302 |
\item \emph{eigen vectors} in tuple |
|
303 |
||
304 |
\begin{itemize} |
|
305 |
\item \texttt{In []: eig(m5)[1]} |
|
306 |
\end{itemize} |
|
307 |
||
308 |
\item Computing \emph{eigen values} using \texttt{eigvals()} |
|
309 |
\begin{verbatim} |
|
310 |
In []: eigvals(m5) |
|
311 |
\end{verbatim} |
|
312 |
||
313 |
\end{itemize} |
|
314 |
\end{frame} |
|
315 |
\begin{frame}[fragile] |
|
316 |
\frametitle{Singular Value Decomposition (\texttt{svd})} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
317 |
\label{sec-15} |
307 | 318 |
|
319 |
$M = U \Sigma V^*$ |
|
320 |
\begin{itemize} |
|
321 |
\item U, an \texttt{mXm} unitary matrix over K. |
|
322 |
\item $\Sigma$ |
|
323 |
, an \texttt{mXn} diagonal matrix with non-negative real numbers on diagonal. |
|
324 |
\item $V^*$ |
|
325 |
, an \texttt{nXn} unitary matrix over K, denotes the conjugate transpose of V. |
|
326 |
\item SVD of matrix \texttt{m5} can be found out as, |
|
327 |
\end{itemize} |
|
328 |
||
329 |
\begin{verbatim} |
|
330 |
In []: svd(m5) |
|
331 |
\end{verbatim} |
|
332 |
\end{frame} |
|
333 |
\begin{frame} |
|
334 |
\frametitle{Summary} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
335 |
\label{sec-16} |
307 | 336 |
|
337 |
\begin{itemize} |
|
338 |
\item Matrices |
|
339 |
||
340 |
\begin{itemize} |
|
341 |
\item creating matrices |
|
342 |
\end{itemize} |
|
343 |
||
344 |
\item Matrix operations |
|
345 |
\item Inverse (\texttt{inv()}) |
|
346 |
\item Determinant (\texttt{det()}) |
|
347 |
\item Norm (\texttt{norm()}) |
|
348 |
\item Eigen values \& vectors (\texttt{eig(), eigvals()}) |
|
349 |
\item Singular Value Decomposition (\texttt{svd()}) |
|
350 |
\end{itemize} |
|
351 |
\end{frame} |
|
352 |
\begin{frame} |
|
353 |
\frametitle{Thank you!} |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
354 |
\label{sec-17} |
307 | 355 |
|
356 |
\begin{block}{} |
|
357 |
\begin{center} |
|
358 |
This spoken tutorial has been produced by the |
|
359 |
\textcolor{blue}{FOSSEE} team, which is funded by the |
|
360 |
\end{center} |
|
361 |
\begin{center} |
|
362 |
\textcolor{blue}{National Mission on Education through \\ |
|
363 |
Information \& Communication Technology \\ |
|
364 |
MHRD, Govt. of India}. |
|
365 |
\end{center} |
|
366 |
\end{block} |
|
367 |
||
368 |
||
369 |
\end{frame} |
|
370 |
||
371 |
\end{document} |