author | Puneeth Chaganti <punchagan@fossee.in> |
Tue, 09 Nov 2010 15:33:47 +0530 | |
changeset 413 | da1f270b07b7 |
parent 394 | 1a79f9ee7f5c |
permissions | -rw-r--r-- |
307 | 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 |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
45 |
: In []: m1 = array([1, 2, 3, 4]) |
307 | 46 |
- Creating a matrix using lists |
47 |
: 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
|
48 |
: In []: m2 = array(l1) |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
49 |
* Exercise 1 |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
50 |
Create a (2, 4) matrix ~m3~ |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
51 |
: 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
|
52 |
: [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
|
53 |
* Solution 1 |
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
54 |
- m3 can be created as, |
307 | 55 |
: In []: m3 = array([[5,6,7,8],[9,10,11,12]]) |
56 |
||
57 |
* Matrix operations |
|
58 |
- Element-wise addition (both matrix should be of order ~mXn~) |
|
59 |
: In []: m3 + m2 |
|
60 |
- Element-wise subtraction (both matrix should be of order ~mXn~) |
|
61 |
: In []: m3 - m2 |
|
62 |
* 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
|
63 |
- Element-wise multiplication using ~m3 * m2~ |
307 | 64 |
: In []: m3 * m2 |
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
65 |
- Matrix Multiplication using ~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
|
66 |
: In []: dot(m3, m2) |
307 | 67 |
: Out []: ValueError: objects are not aligned |
68 |
||
69 |
* Matrix Multiplication (cont'd) |
|
70 |
- Create two compatible matrices of order ~nXm~ and ~mXr~ |
|
71 |
: In []: m1.shape |
|
72 |
- matrix m1 is of order ~1 X 4~ |
|
73 |
- Creating another matrix of order ~4 X 2~ |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
74 |
: In []: m4 = array([[1,2],[3,4],[5,6],[7,8]]) |
307 | 75 |
- 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
|
76 |
: In []: dot(m1, m4) |
307 | 77 |
* Recall from ~array~ |
78 |
- The functions |
|
79 |
- ~identity(n)~ - |
|
80 |
creates an identity matrix of order ~nXn~ |
|
81 |
- ~zeros((m,n))~ - |
|
82 |
creates a matrix of order ~mXn~ with 0's |
|
83 |
- ~zeros_like(A)~ - |
|
84 |
creates a matrix with 0's similar to the shape of matrix ~A~ |
|
85 |
- ~ones((m,n))~ |
|
86 |
creates a matrix of order ~mXn~ with 1's |
|
87 |
- ~ones_like(A)~ |
|
88 |
creates a matrix with 1's similar to the shape of matrix ~A~ |
|
89 |
Can also be used with matrices |
|
90 |
||
91 |
* More matrix operations |
|
92 |
Transpose of a matrix |
|
93 |
: In []: m4.T |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
94 |
* Exercise 2 : Frobenius norm \& inverse |
307 | 95 |
Find out the Frobenius norm of inverse of a ~4 X 4~ matrix. |
96 |
: |
|
97 |
The matrix is |
|
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
98 |
: m5 = arange(1,17).reshape(4,4) |
307 | 99 |
- Inverse of A, |
100 |
- |
|
101 |
#+begin_latex |
|
102 |
$A^{-1} = inv(A)$ |
|
103 |
#+end_latex |
|
104 |
- Frobenius norm is defined as, |
|
105 |
- |
|
106 |
#+begin_latex |
|
107 |
$||A||_F = [\sum_{i,j} abs(a_{i,j})^2]^{1/2}$ |
|
108 |
#+end_latex |
|
109 |
||
394
1a79f9ee7f5c
made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents:
307
diff
changeset
|
110 |
* Exercise 3 : Infinity norm |
307 | 111 |
Find the infinity norm of the matrix ~im5~ |
112 |
: |
|
113 |
- Infinity norm is defined as, |
|
114 |
#+begin_latex |
|
115 |
$max([\sum_{i} abs(a_{i})^2])$ |
|
116 |
#+end_latex |
|
117 |
* ~norm()~ method |
|
118 |
- Frobenius norm |
|
119 |
: In []: norm(im5) |
|
120 |
- Infinity norm |
|
121 |
: In []: norm(im5, ord=inf) |
|
122 |
* Determinant |
|
123 |
Find out the determinant of the matrix m5 |
|
124 |
: |
|
125 |
- determinant can be found out using |
|
126 |
- ~det(A)~ - returns the determinant of matrix ~A~ |
|
127 |
* eigen values \& eigen vectors |
|
128 |
Find out the eigen values and eigen vectors of the matrix ~m5~. |
|
129 |
: |
|
130 |
- eigen values and vectors can be found out using |
|
131 |
: In []: eig(m5) |
|
132 |
returns a tuple of /eigen values/ and /eigen vectors/ |
|
133 |
- /eigen values/ in tuple |
|
134 |
- ~In []: eig(m5)[0]~ |
|
135 |
- /eigen vectors/ in tuple |
|
136 |
- ~In []: eig(m5)[1]~ |
|
137 |
- Computing /eigen values/ using ~eigvals()~ |
|
138 |
: In []: eigvals(m5) |
|
139 |
* Singular Value Decomposition (~svd~) |
|
140 |
#+begin_latex |
|
141 |
$M = U \Sigma V^*$ |
|
142 |
#+end_latex |
|
143 |
- U, an ~mXm~ unitary matrix over K. |
|
144 |
- |
|
145 |
#+begin_latex |
|
146 |
$\Sigma$ |
|
147 |
#+end_latex |
|
148 |
, an ~mXn~ diagonal matrix with non-negative real numbers on diagonal. |
|
149 |
- |
|
150 |
#+begin_latex |
|
151 |
$V^*$ |
|
152 |
#+end_latex |
|
153 |
, an ~nXn~ unitary matrix over K, denotes the conjugate transpose of V. |
|
154 |
- SVD of matrix ~m5~ can be found out as, |
|
155 |
: In []: svd(m5) |
|
156 |
* Summary |
|
157 |
- Matrices |
|
158 |
- creating matrices |
|
159 |
- Matrix operations |
|
160 |
- Inverse (~inv()~) |
|
161 |
- Determinant (~det()~) |
|
162 |
- Norm (~norm()~) |
|
163 |
- Eigen values \& vectors (~eig(), eigvals()~) |
|
164 |
- Singular Value Decomposition (~svd()~) |
|
165 |
||
166 |
* Thank you! |
|
167 |
#+begin_latex |
|
168 |
\begin{block}{} |
|
169 |
\begin{center} |
|
170 |
This spoken tutorial has been produced by the |
|
171 |
\textcolor{blue}{FOSSEE} team, which is funded by the |
|
172 |
\end{center} |
|
173 |
\begin{center} |
|
174 |
\textcolor{blue}{National Mission on Education through \\ |
|
175 |
Information \& Communication Technology \\ |
|
176 |
MHRD, Govt. of India}. |
|
177 |
\end{center} |
|
178 |
\end{block} |
|
179 |
#+end_latex |
|
180 |
||
181 |