matrices/script.rst
author bhanu
Thu, 11 Nov 2010 02:16:07 +0530
changeset 477 0406115dccd1
parent 404 3117f104c577
child 478 5083394605e0
permissions -rw-r--r--
language check done for `matrices`
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
319
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
     1
.. Objectives
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
     2
.. ----------
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
     3
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
     4
.. At the end of this tutorial, you will be able to 
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
     5
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
     6
.. 1. Create matrices using data.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
     7
.. #. Create matrices from lists.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
     8
.. #. Basic matrix operations.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
     9
.. #. Use ``inv()`` function to find inverse of a matrix.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    10
.. #. Use ``det()`` function to find determinant of a matrix.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    11
.. #. Use ``eig()`` and ``eigvals()`` functions to find eigen values
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    12
      and vectors
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    13
.. #. Use ``norm()`` function to find norm of a matrix.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    14
.. #. Use ``svd()`` function to find singular value decomposition of a
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    15
      matrix.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    16
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    17
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    18
.. Prerequisites
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    19
.. -------------
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    20
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    21
..   1. should have ``ipython`` and ``pylab`` installed. 
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    22
..   #. getting started with ``ipython``.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    23
..   #. getting started with lists.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    24
..   #. getting started with arrays.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    25
..   #. accessing part of arrays.
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    26
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    27
     
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    28
.. Author              : Anoop Jacob Thomas <anoop@fossee.in>
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    29
   Internal Reviewer   : 
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    30
   External Reviewer   :
477
0406115dccd1 language check done for `matrices`
bhanu
parents: 404
diff changeset
    31
   Language Reviewer   : Bhanukiran
319
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    32
   Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
e8c02b3c51ac changed headers of scripts(objectives and prerequisites).
Anoop Jacob Thomas<anoop@fossee.in>
parents: 307
diff changeset
    33
404
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
    34
.. #[punch: please mark the exercises, using the syntax we decided upon.]
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    35
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    36
========
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    37
Matrices
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    38
========
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    39
{{{ show the welcome slide }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    40
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    41
Welcome to the spoken tutorial on Matrices.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    42
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    43
{{{ switch to next slide, outline slide }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    44
307
1a73dddb1d05 added slides for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 287
diff changeset
    45
In this tutorial we will learn about matrices, creating matrices using
477
0406115dccd1 language check done for `matrices`
bhanu
parents: 404
diff changeset
    46
direct data, converting a list and matrix operations. Finding
404
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
    47
inverse of a matrix, determinant of a matrix, eigen values and eigen
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
    48
vectors of a matrix, norm and singular value decomposition of
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
    49
matrices.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    50
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    51
{{{ creating a matrix }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    52
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    53
All matrix operations are done using arrays. Thus all the operations
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    54
on arrays are valid on matrices also. A matrix may be created as,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    55
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    56
394
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
    57
    m1 = array([1,2,3,4])
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    58
340
3951809e75bd Changes suggested for Matrices LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 319
diff changeset
    59
3951809e75bd Changes suggested for Matrices LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 319
diff changeset
    60
.. #[Puneeth: don't use ``matrix``. Use ``array``. The whole script will
3951809e75bd Changes suggested for Matrices LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 319
diff changeset
    61
.. have to be fixed.]
3951809e75bd Changes suggested for Matrices LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 319
diff changeset
    62
477
0406115dccd1 language check done for `matrices`
bhanu
parents: 404
diff changeset
    63
Using the method ``shape`` we can find out the shape or size of the
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    64
matrix,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    65
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    66
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    67
    m1.shape
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    68
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    69
Since it is a one row four column matrix it returned a tuple, one by
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    70
four.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    71
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    72
A list can be converted to a matrix as follows,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    73
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    74
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    75
    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: 340
diff changeset
    76
    m2 = array(l1)
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
    77
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
    78
{{{ switch to next slide, exercise 1}}}
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    79
394
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
    80
Pause here and create a two dimensional matrix m3 of order 2 by 4 with
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
    81
elements 5, 6, 7, 8, 9, 10, 11, 12.
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
    82
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
    83
{{{ switch to next slide, solution }}}
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
    84
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
    85
m3 can be created as,
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    86
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    87
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    88
    m3 = array([[5,6,7,8],[9,10,11,12]])
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    89
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    90
{{{ switch to next slide, matrix operations }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    91
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    92
We can do matrix addition and subtraction as,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    93
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    94
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    95
    m3 + m2
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    96
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    97
does element by element addition, thus matrix addition.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    98
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
    99
Similarly,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   100
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   101
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   102
    m3 - m2
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   103
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   104
it does matrix subtraction, that is element by element
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   105
subtraction. Now let us try,
287
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   106
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   107
{{{ Switch to next slide, Matrix multiplication }}}
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   108
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   109
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   110
    m3 * m2
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   111
394
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
   112
Note that in arrays ``m3 * m2`` does element wise multiplication and not
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
   113
matrix multiplication,
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   114
394
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
   115
And matrix multiplication in matrices are done using the function ``dot()``
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   116
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   117
394
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
   118
    dot(m3, m2)
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
   119
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
   120
but due to size mismatch the multiplication could not be done and it
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
   121
returned an error,
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   122
307
1a73dddb1d05 added slides for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 287
diff changeset
   123
{{{ switch to next slide, Matrix multiplication (cont'd) }}}
1a73dddb1d05 added slides for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 287
diff changeset
   124
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   125
Now let us see an example for matrix multiplication. For doing matrix
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   126
multiplication we need to have two matrices of the order n by m and m
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   127
by r and the resulting matrix will be of the order n by r. Thus let us
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   128
first create two matrices which are compatible for multiplication.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   129
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   130
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   131
    m1.shape
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   132
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   133
matrix m1 is of the shape one by four, let us create another one of
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   134
the order four by two,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   135
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   136
394
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
   137
    m4 = array([[1,2],[3,4],[5,6],[7,8]])
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
   138
    dot(m1, m4)
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   139
394
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
   140
thus the function ``dot()`` can be used for matrix multiplication.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   141
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   142
{{{ switch to next slide, recall from arrays }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   143
307
1a73dddb1d05 added slides for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 287
diff changeset
   144
As we already saw in arrays, the functions ``identity()`` which
1a73dddb1d05 added slides for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 287
diff changeset
   145
creates an identity matrix of the order n by n, ``zeros()`` which
1a73dddb1d05 added slides for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 287
diff changeset
   146
creates a matrix of the order m by n with all zeros, ``zeros_like()``
1a73dddb1d05 added slides for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 287
diff changeset
   147
which creates a matrix with zeros with the shape of the matrix passed,
1a73dddb1d05 added slides for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 287
diff changeset
   148
``ones()`` which creates a matrix of order m by n with all ones,
1a73dddb1d05 added slides for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 287
diff changeset
   149
``ones_like()`` which creates a matrix with ones with the shape of the
1a73dddb1d05 added slides for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 287
diff changeset
   150
matrix passed. These functions can also be used with matrices.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   151
307
1a73dddb1d05 added slides for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 287
diff changeset
   152
{{{ switch to next slide, more matrix operations }}}
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   153
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   154
To find out the transpose of a matrix we can do,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   155
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   156
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   157
    print m4
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   158
    m4.T
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   159
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   160
Matrix name dot capital T will give the transpose of a matrix
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   161
287
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   162
{{{ switch to next slide, Frobenius norm of inverse of matrix }}}
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   163
404
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   164
.. #[punch: arange has not been introduced.]
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   165
287
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   166
Now let us try to find out the Frobenius norm of inverse of a 4 by 4
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   167
matrix, the matrix being,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   168
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   169
394
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
   170
    m5 = arange(1,17).reshape(4,4)
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   171
    print m5
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   172
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   173
The inverse of a matrix A, A raise to minus one is also called the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   174
reciprocal matrix such that A multiplied by A inverse will give 1. The
287
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   175
Frobenius norm of a matrix is defined as square root of sum of squares
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   176
of elements in the matrix. Pause here and try to solve the problem
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   177
yourself, the inverse of a matrix can be found using the function
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   178
``inv(A)``.
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   179
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   180
And here is the solution, first let us find the inverse of matrix m5.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   181
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   182
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   183
    im5 = inv(m5)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   184
404
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   185
.. #[punch: we don't need to show this way of calculating the norm, do
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   186
.. we? even if we do, we should show it in the "array style".
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   187
.. something like:
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   188
.. sqrt(sum(each * each))]
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   189
287
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   190
And the Frobenius norm of the matrix ``im5`` can be found out as,
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   191
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   192
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   193
    sum = 0
394
1a79f9ee7f5c made changes to script, matrices, using array() instead of matrix() now.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 340
diff changeset
   194
    for each in im5.flatten():
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   195
        sum += each * each
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   196
    print sqrt(sum)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   197
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   198
{{{ switch to next slide, infinity norm }}}
404
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   199
.. #[punch: similarly for this section.]
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   200
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   201
Now try to find out the infinity norm of the matrix im5. The infinity
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   202
norm of a matrix is defined as the maximum value of sum of the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   203
absolute of elements in each row. Pause here and try to solve the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   204
problem yourself.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   205
404
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   206
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   207
The solution for the problem is,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   208
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   209
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   210
    sum_rows = []
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   211
    for i in im5:
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   212
        sum_rows.append(abs(i).sum())
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   213
    print max(sum_rows)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   214
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   215
{{{ switch to slide the ``norm()`` method }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   216
287
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   217
Well! to find the Frobenius norm and Infinity norm we have an even easier
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   218
method, and let us see that now.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   219
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   220
The norm of a matrix can be found out using the method
287
d9507624eb8f added questions for matrices.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 261
diff changeset
   221
``norm()``. Inorder to find out the Frobenius norm of the matrix im5,
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   222
we do,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   223
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   224
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   225
    norm(im5)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   226
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   227
And to find out the Infinity norm of the matrix im5, we do,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   228
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   229
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   230
    norm(im5,ord=inf)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   231
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   232
This is easier when compared to the code we wrote. Do ``norm``
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   233
question mark to read up more about ord and the possible type of norms
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   234
the norm function produces.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   235
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   236
{{{ switch to next slide, determinant }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   237
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   238
Now let us find out the determinant of a the matrix m5. 
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   239
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   240
The determinant of a square matrix can be obtained using the function
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   241
``det()`` and the determinant of m5 can be found out as,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   242
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   243
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   244
    det(m5)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   245
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   246
{{{ switch to next slide, eigen vectors and eigen values }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   247
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   248
The eigen values and eigen vector of a square matrix can be computed
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   249
using the function ``eig()`` and ``eigvals()``.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   250
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   251
Let us find out the eigen values and eigen vectors of the matrix
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   252
m5. We can do it as,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   253
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   254
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   255
    eig(m5)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   256
404
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   257
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   258
.. #[punch: has the tuple word been introduced?]
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   259
261
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   260
Note that it returned a tuple of two matrices. The first element in
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   261
the tuple are the eigen values and the second element in the tuple are
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   262
the eigen vectors. Thus the eigen values are,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   263
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   264
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   265
    eig(m5)[0]
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   266
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   267
and the eigen vectors are,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   268
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   269
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   270
    eig(m5)[1]
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   271
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   272
The eigen values can also be computed using the function ``eigvals()`` as,
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   273
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   274
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   275
    eigvals(m5)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   276
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   277
{{{ switch to next slide, singular value decomposition }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   278
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   279
Now let us learn how to do the singular value decomposition or S V D
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   280
of a matrix.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   281
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   282
Suppose M is an m×n matrix whose entries come from the field K, which
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   283
is either the field of real numbers or the field of complex
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   284
numbers. Then there exists a factorization of the form
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   285
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   286
    M = U\Sigma V star
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   287
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   288
where U is an (m by m) unitary matrix over K, the matrix \Sigma is an
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   289
(m by n) diagonal matrix with nonnegative real numbers on the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   290
diagonal, and V*, an (n by n) unitary matrix over K, denotes the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   291
conjugate transpose of V. Such a factorization is called the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   292
singular-value decomposition of M.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   293
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   294
The SVD of matrix m5 can be found as
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   295
::
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   296
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   297
    svd(m5)
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   298
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   299
Notice that it returned a tuple of 3 elements. The first one U the
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   300
next one Sigma and the third one V star.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   301
    
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   302
{{{ switch to next slide, recap slide }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   303
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   304
So this brings us to the end of this tutorial. In this tutorial, we
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   305
learned about matrices, creating matrices, matrix operations, inverse
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   306
of matrices, determinant, norm, eigen values and vectors and singular
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   307
value decomposition of matrices.
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   308
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   309
{{{ switch to next slide, thank you }}}
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   310
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   311
Thank you!
c7f0069d698a added base scripts and questions except for matrices and other-type-of-plots. previous commit only removed unwanted files.
anoop
parents:
diff changeset
   312
340
3951809e75bd Changes suggested for Matrices LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 319
diff changeset
   313
.. 
3951809e75bd Changes suggested for Matrices LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 319
diff changeset
   314
   Local Variables:
3951809e75bd Changes suggested for Matrices LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 319
diff changeset
   315
   mode: rst
3951809e75bd Changes suggested for Matrices LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 319
diff changeset
   316
   indent-tabs-mode: nil
3951809e75bd Changes suggested for Matrices LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 319
diff changeset
   317
   sentence-end-double-space: nil
404
3117f104c577 Changes to matrices script.
Puneeth Chaganti <punchagan@fossee.in>
parents: 394
diff changeset
   318
   fill-column: 70
340
3951809e75bd Changes suggested for Matrices LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 319
diff changeset
   319
   End: