--- a/matrices/script.rst Mon Nov 08 02:12:28 2010 +0530
+++ b/matrices/script.rst Thu Nov 11 02:28:55 2010 +0530
@@ -30,6 +30,7 @@
External Reviewer :
Checklist OK? : <put date stamp here, if OK> [2010-10-05]
+.. #[punch: please mark the exercises, using the syntax we decided upon.]
========
Matrices
@@ -41,9 +42,10 @@
{{{ switch to next slide, outline slide }}}
In this tutorial we will learn about matrices, creating matrices using
-direct data, by converting a list, matrix operations. Finding inverse
-of a matrix, determinant of a matrix, eigen values and eigen vectors
-of a matrix, norm and singular value decomposition of matrices.
+direct data, by converting a list and matrix operations. Finding
+inverse of a matrix, determinant of a matrix, eigen values and eigen
+vectors of a matrix, norm and singular value decomposition of
+matrices.
{{{ creating a matrix }}}
@@ -51,7 +53,7 @@
on arrays are valid on matrices also. A matrix may be created as,
::
- m1 = matrix([1,2,3,4])
+ m1 = array([1,2,3,4])
.. #[Puneeth: don't use ``matrix``. Use ``array``. The whole script will
@@ -70,10 +72,16 @@
::
l1 = [[1,2,3,4],[5,6,7,8]]
- m2 = matrix(l1)
+ m2 = array(l1)
+
+{{{ switch to next slide, exercise 1}}}
-Note that all matrix operations are done using arrays, so a matrix may
-also be created as
+Pause here and create a two dimensional matrix m3 of order 2 by 4 with
+elements 5, 6, 7, 8, 9, 10, 11, 12.
+
+{{{ switch to next slide, solution }}}
+
+m3 can be created as,
::
m3 = array([[5,6,7,8],[9,10,11,12]])
@@ -100,17 +108,16 @@
m3 * m2
-Note that in arrays ``array(A) star array(B)`` does element wise
-multiplication and not matrix multiplication, but unlike arrays, the
-operation ``matrix(A) star matrix(B)`` does matrix multiplication and
-not element wise multiplication. And in this case since the sizes are
-not compatible for multiplication it returned an error.
+Note that in arrays ``m3 * m2`` does element wise multiplication and not
+matrix multiplication,
-And element wise multiplication in matrices are done using the
-function ``multiply()``
+And matrix multiplication in matrices are done using the function ``dot()``
::
- multiply(m3,m2)
+ dot(m3, m2)
+
+but due to size mismatch the multiplication could not be done and it
+returned an error,
{{{ switch to next slide, Matrix multiplication (cont'd) }}}
@@ -126,11 +133,10 @@
the order four by two,
::
- m4 = matrix([[1,2],[3,4],[5,6],[7,8]])
- m1 * m4
+ m4 = array([[1,2],[3,4],[5,6],[7,8]])
+ dot(m1, m4)
-thus unlike in array object ``star`` can be used for matrix multiplication
-in matrix object.
+thus the function ``dot()`` can be used for matrix multiplication.
{{{ switch to next slide, recall from arrays }}}
@@ -154,11 +160,13 @@
{{{ switch to next slide, Frobenius norm of inverse of matrix }}}
+.. #[punch: arange has not been introduced.]
+
Now let us try to find out the Frobenius norm of inverse of a 4 by 4
matrix, the matrix being,
::
- m5 = matrix(arange(1,17).reshape(4,4))
+ m5 = arange(1,17).reshape(4,4)
print m5
The inverse of a matrix A, A raise to minus one is also called the
@@ -173,21 +181,28 @@
im5 = inv(m5)
+.. #[punch: we don't need to show this way of calculating the norm, do
+.. we? even if we do, we should show it in the "array style".
+.. something like:
+.. sqrt(sum(each * each))]
+
And the Frobenius norm of the matrix ``im5`` can be found out as,
::
sum = 0
- for each in array(im5.flatten())[0]:
+ for each in im5.flatten():
sum += each * each
print sqrt(sum)
{{{ switch to next slide, infinity norm }}}
+.. #[punch: similarly for this section.]
Now try to find out the infinity norm of the matrix im5. The infinity
norm of a matrix is defined as the maximum value of sum of the
absolute of elements in each row. Pause here and try to solve the
problem yourself.
+
The solution for the problem is,
::
@@ -238,6 +253,9 @@
eig(m5)
+
+.. #[punch: has the tuple word been introduced?]
+
Note that it returned a tuple of two matrices. The first element in
the tuple are the eigen values and the second element in the tuple are
the eigen vectors. Thus the eigen values are,
@@ -296,5 +314,5 @@
mode: rst
indent-tabs-mode: nil
sentence-end-double-space: nil
- fill-column: 75
+ fill-column: 70
End: