20 |
20 |
21 Welcome to the spoken tutorial on Matrices. |
21 Welcome to the spoken tutorial on Matrices. |
22 |
22 |
23 {{{ switch to next slide, outline slide }}} |
23 {{{ switch to next slide, outline slide }}} |
24 |
24 |
25 In this tutorial we will learn about matrices, creating matrices and |
25 In this tutorial we will learn about matrices, creating matrices using |
26 matrix operations. |
26 direct data, by converting a list, matrix operations. Finding inverse |
|
27 of a matrix, determinant of a matrix, eigen values and eigen vectors |
|
28 of a matrix, norm and singular value decomposition of matrices. |
27 |
29 |
28 {{{ creating a matrix }}} |
30 {{{ creating a matrix }}} |
29 |
31 |
30 All matrix operations are done using arrays. Thus all the operations |
32 All matrix operations are done using arrays. Thus all the operations |
31 on arrays are valid on matrices also. A matrix may be created as, |
33 on arrays are valid on matrices also. A matrix may be created as, |
84 function ``multiply()`` |
88 function ``multiply()`` |
85 :: |
89 :: |
86 |
90 |
87 multiply(m3,m2) |
91 multiply(m3,m2) |
88 |
92 |
|
93 {{{ switch to next slide, Matrix multiplication (cont'd) }}} |
|
94 |
89 Now let us see an example for matrix multiplication. For doing matrix |
95 Now let us see an example for matrix multiplication. For doing matrix |
90 multiplication we need to have two matrices of the order n by m and m |
96 multiplication we need to have two matrices of the order n by m and m |
91 by r and the resulting matrix will be of the order n by r. Thus let us |
97 by r and the resulting matrix will be of the order n by r. Thus let us |
92 first create two matrices which are compatible for multiplication. |
98 first create two matrices which are compatible for multiplication. |
93 :: |
99 :: |
104 thus unlike in array object ``star`` can be used for matrix multiplication |
110 thus unlike in array object ``star`` can be used for matrix multiplication |
105 in matrix object. |
111 in matrix object. |
106 |
112 |
107 {{{ switch to next slide, recall from arrays }}} |
113 {{{ switch to next slide, recall from arrays }}} |
108 |
114 |
109 As we already saw in arrays, the functions ``identity()``, |
115 As we already saw in arrays, the functions ``identity()`` which |
110 ``zeros()``, ``zeros_like()``, ``ones()``, ``ones_like()`` may also be |
116 creates an identity matrix of the order n by n, ``zeros()`` which |
111 used with matrices. |
117 creates a matrix of the order m by n with all zeros, ``zeros_like()`` |
112 |
118 which creates a matrix with zeros with the shape of the matrix passed, |
113 {{{ switch to next slide, matrix operations }}} |
119 ``ones()`` which creates a matrix of order m by n with all ones, |
|
120 ``ones_like()`` which creates a matrix with ones with the shape of the |
|
121 matrix passed. These functions can also be used with matrices. |
|
122 |
|
123 {{{ switch to next slide, more matrix operations }}} |
114 |
124 |
115 To find out the transpose of a matrix we can do, |
125 To find out the transpose of a matrix we can do, |
116 :: |
126 :: |
117 |
127 |
118 print m4 |
128 print m4 |
119 m4.T |
129 m4.T |
120 |
130 |
121 Matrix name dot capital T will give the transpose of a matrix |
131 Matrix name dot capital T will give the transpose of a matrix |
122 |
132 |
123 {{{ switch to next slide, Euclidean norm of inverse of matrix }}} |
133 {{{ switch to next slide, Frobenius norm of inverse of matrix }}} |
124 |
134 |
125 Now let us try to find out the Euclidean norm of inverse of a 4 by 4 |
135 Now let us try to find out the Frobenius norm of inverse of a 4 by 4 |
126 matrix, the matrix being, |
136 matrix, the matrix being, |
127 :: |
137 :: |
128 |
138 |
129 m5 = matrix(arange(1,17).reshape(4,4)) |
139 m5 = matrix(arange(1,17).reshape(4,4)) |
130 print m5 |
140 print m5 |
131 |
141 |
132 The inverse of a matrix A, A raise to minus one is also called the |
142 The inverse of a matrix A, A raise to minus one is also called the |
133 reciprocal matrix such that A multiplied by A inverse will give 1. The |
143 reciprocal matrix such that A multiplied by A inverse will give 1. The |
134 Euclidean norm or the Frobenius norm of a matrix is defined as square |
144 Frobenius norm of a matrix is defined as square root of sum of squares |
135 root of sum of squares of elements in the matrix. Pause here and try |
145 of elements in the matrix. Pause here and try to solve the problem |
136 to solve the problem yourself, the inverse of a matrix can be found |
146 yourself, the inverse of a matrix can be found using the function |
137 using the function ``inv(A)``. |
147 ``inv(A)``. |
138 |
148 |
139 And here is the solution, first let us find the inverse of matrix m5. |
149 And here is the solution, first let us find the inverse of matrix m5. |
140 :: |
150 :: |
141 |
151 |
142 im5 = inv(m5) |
152 im5 = inv(m5) |
143 |
153 |
144 And the euclidean norm of the matrix ``im5`` can be found out as, |
154 And the Frobenius norm of the matrix ``im5`` can be found out as, |
145 :: |
155 :: |
146 |
156 |
147 sum = 0 |
157 sum = 0 |
148 for each in array(im5.flatten())[0]: |
158 for each in array(im5.flatten())[0]: |
149 sum += each * each |
159 sum += each * each |
164 sum_rows.append(abs(i).sum()) |
174 sum_rows.append(abs(i).sum()) |
165 print max(sum_rows) |
175 print max(sum_rows) |
166 |
176 |
167 {{{ switch to slide the ``norm()`` method }}} |
177 {{{ switch to slide the ``norm()`` method }}} |
168 |
178 |
169 Well! to find the Euclidean norm and Infinity norm we have an even easier |
179 Well! to find the Frobenius norm and Infinity norm we have an even easier |
170 method, and let us see that now. |
180 method, and let us see that now. |
171 |
181 |
172 The norm of a matrix can be found out using the method |
182 The norm of a matrix can be found out using the method |
173 ``norm()``. Inorder to find out the Euclidean norm of the matrix im5, |
183 ``norm()``. Inorder to find out the Frobenius norm of the matrix im5, |
174 we do, |
184 we do, |
175 :: |
185 :: |
176 |
186 |
177 norm(im5) |
187 norm(im5) |
178 |
188 |