Package controlsystems :: Module types :: Class Matrix
[hide private]

Class Matrix

source code

object --+    
         |    
      list --+
             |
            Matrix

Matrix type

This class implements the Matrix type, based on the Python lists. The matrix object is a list of lists and have 2 properties ('cols' and 'rows'), that store the sizes of the matrix. For example:

>>> a = Matrix([
...     [1, 2, 3],
...     [2, 3, 4],
...     [3, 4, 5],
... ])
>>>
>>> print a
1    2    3
2    3    4
3    4    5
>>>
>>> a.rows
3
>>> a.cols
3
Instance Methods [hide private]
new list
__init__(self, mat)
Initialization of Matrix object
source code
 
__str__(self)
String representation
source code
 
__call__(self, row, col=None)
Callable object
source code
 
__add__(self, mat)
Operation of addition
source code
 
__sub__(self, mat)
Operation of subtraction
source code
 
__mul__(self, mat)
Operation of multiplication of polynomials
source code
 
mult(self, num)
Operation of multiplication between numbers and matrices
source code
 
transpose(self)
Transpose of matrix
source code

Inherited from list: __contains__, __delitem__, __delslice__, __eq__, __ge__, __getattribute__, __getitem__, __getslice__, __gt__, __iadd__, __imul__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __repr__, __reversed__, __rmul__, __setitem__, __setslice__, __sizeof__, append, count, extend, index, insert, pop, remove, reverse, sort

Inherited from object: __delattr__, __format__, __reduce__, __reduce_ex__, __setattr__, __subclasshook__

Class Variables [hide private]

Inherited from list: __hash__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, mat)
(Constructor)

source code 

Initialization of Matrix object

This method initialize a Matrix object, calculating the values of the properties 'cols' and 'rows'.

Returns: new list
Overrides: object.__init__

__str__(self)
(Informal representation operator)

source code 
String representation

This method returns the string representation of matrices. For
example:

    1    2    3
    2    3    4
    3    4    5

Overrides: object.__str__

__call__(self, row, col=None)
(Call operator)

source code 

Callable object

This method returns a row Matrix object if a parameter is used and a number if two parameters are used. For example:

>>> a = Matrix([
...     [1, 2],
...     [3, 4],
... ])
>>>
>>> b = a(1)
>>> print b
3    4
>>> type(b)
<class 'controlsystems.types.Matrix'>
>>>
>>> c = a(0, 0)
>>> print c
1
>>> type(c)
<type 'int'>

__add__(self, mat)
(Addition operator)

source code 

Operation of addition

This method returns a Matrix object with the result of the addition of the Matrix 'self' and the Matrix 'mat'. For example:

>>> a = Matrix([
...     [1, 2],
...     [3, 4],
... ])
>>>
>>> b = Matrix([
...     [2, 3],
...     [4, 5],
... ])
>>>
>>> c = a + b
>>> print c
3    5
7    9
>>> type(c)
<class 'controlsystems.types.Matrix'>
Overrides: list.__add__

__sub__(self, mat)
(Subtraction operator)

source code 

Operation of subtraction

This method returns a Matrix object with the result of the subtraction of the Matrix 'self' and the Matrix 'mat'. For example:

>>> a = Matrix([
...     [2, 3],
...     [4, 5],
... ])
>>>
>>> b = Matrix([
...     [1, 2],
...     [3, 4],
... ])
>>>
>>> c = a - b
>>> print c
1    1  
1    1
>>>
>>> type(c)
<class 'controlsystems.types.Matrix'>

This method is based on __add__ method

__mul__(self, mat)

source code 

Operation of multiplication of polynomials

This method returns a Matrix object with the result of the multiplication of the Matrix 'self' and the Matrix 'mat'. For example:

>>> a = Matrix([
...     [1, 2],
...     [3, 4],
... ])
>>>
>>> b = Matrix([
...     [2, 3],
...     [4, 5],
... ])
>>>
>>> c = a * b
>>> print c
10    13
22    29
>>>
>>> type(c)
<class 'controlsystems.types.Matrix'>
Overrides: list.__mul__

mult(self, num)

source code 

Operation of multiplication between numbers and matrices

This method returns a Matrix object with the result of the multiplication of the Matrix 'self' and the number 'num'. For example:

>>> a = Matrix([
...     [1, 2],
...     [3, 4],
... ])
>>>
>>> b = a.mult(5)
>>> print b
5    10
15   20
>>>
>>> type(b)
<class 'controlsystems.types.Matrix'>

transpose(self)

source code 

Transpose of matrix

This method returns a Matrix object with the transpose of the Matrix 'self'. For example:

>>> a = Matrix([
...     [1, 2],
...     [3, 4],
... ])
>>>
>>> b = a.transpose()
>>> print b
1    3
2    4
>>>
>>> type(b)
<class 'controlsystems.types.Matrix'>