68 |
68 |
69 m3 - m2 |
69 m3 - m2 |
70 |
70 |
71 it does matrix subtraction, that is element by element |
71 it does matrix subtraction, that is element by element |
72 subtraction. Now let us try, |
72 subtraction. Now let us try, |
|
73 |
|
74 {{{ Switch to next slide, Matrix multiplication }}} |
73 :: |
75 :: |
74 |
76 |
75 m3 * m2 |
77 m3 * m2 |
76 |
78 |
77 Note that in arrays ``array(A) star array(B)`` does element wise |
79 Note that in arrays ``array(A) star array(B)`` does element wise |
118 print m4 |
120 print m4 |
119 m4.T |
121 m4.T |
120 |
122 |
121 Matrix name dot capital T will give the transpose of a matrix |
123 Matrix name dot capital T will give the transpose of a matrix |
122 |
124 |
123 {{{ switch to next slide, Euclidean norm of inverse of matrix }}} |
125 {{{ switch to next slide, Frobenius norm of inverse of matrix }}} |
124 |
126 |
125 Now let us try to find out the Euclidean norm of inverse of a 4 by 4 |
127 Now let us try to find out the Frobenius norm of inverse of a 4 by 4 |
126 matrix, the matrix being, |
128 matrix, the matrix being, |
127 :: |
129 :: |
128 |
130 |
129 m5 = matrix(arange(1,17).reshape(4,4)) |
131 m5 = matrix(arange(1,17).reshape(4,4)) |
130 print m5 |
132 print m5 |
131 |
133 |
132 The inverse of a matrix A, A raise to minus one is also called the |
134 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 |
135 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 |
136 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 |
137 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 |
138 yourself, the inverse of a matrix can be found using the function |
137 using the function ``inv(A)``. |
139 ``inv(A)``. |
138 |
140 |
139 And here is the solution, first let us find the inverse of matrix m5. |
141 And here is the solution, first let us find the inverse of matrix m5. |
140 :: |
142 :: |
141 |
143 |
142 im5 = inv(m5) |
144 im5 = inv(m5) |
143 |
145 |
144 And the euclidean norm of the matrix ``im5`` can be found out as, |
146 And the Frobenius norm of the matrix ``im5`` can be found out as, |
145 :: |
147 :: |
146 |
148 |
147 sum = 0 |
149 sum = 0 |
148 for each in array(im5.flatten())[0]: |
150 for each in array(im5.flatten())[0]: |
149 sum += each * each |
151 sum += each * each |
164 sum_rows.append(abs(i).sum()) |
166 sum_rows.append(abs(i).sum()) |
165 print max(sum_rows) |
167 print max(sum_rows) |
166 |
168 |
167 {{{ switch to slide the ``norm()`` method }}} |
169 {{{ switch to slide the ``norm()`` method }}} |
168 |
170 |
169 Well! to find the Euclidean norm and Infinity norm we have an even easier |
171 Well! to find the Frobenius norm and Infinity norm we have an even easier |
170 method, and let us see that now. |
172 method, and let us see that now. |
171 |
173 |
172 The norm of a matrix can be found out using the method |
174 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, |
175 ``norm()``. Inorder to find out the Frobenius norm of the matrix im5, |
174 we do, |
176 we do, |
175 :: |
177 :: |
176 |
178 |
177 norm(im5) |
179 norm(im5) |
|
180 |
|
181 Euclidean norm is also called Frobenius norm. |
178 |
182 |
179 And to find out the Infinity norm of the matrix im5, we do, |
183 And to find out the Infinity norm of the matrix im5, we do, |
180 :: |
184 :: |
181 |
185 |
182 norm(im5,ord=inf) |
186 norm(im5,ord=inf) |