CAPD::DynSys Library
6.0.0
|
This file provides a short description on how to use class Matrix from CAPD package - for more details see header file "capd/vectalg/Matrix.h"
Content of this file:
The class Matrix is defined in the namespace capd::vectalg. The template class Matrix has three parameters - type of elements stored in a matrix, number of rows and number of columns
If both arguments rows and cols are greater than zero, the matrix is represented as an internal one-dimensional array with suitable indexing. If rows or cols is equal to zero, the matrix has a pointer to the allocated array
The following lines define new names for four dimensional vectors
The following lines define new names for vectors of arbitrary length
The following lines define new names for square matrices 4x4 both for doubles and intervals
The following lines define new names for matrices of arbitrary size
The following line creates a 4x4 matrix filled with zeros
The matrix N will be a 4x5 dimensional interval matrix filled with zeros
If one wishes to initialize the matrix when creating an object, he or she can define a table which contains the rows of a matrix and send it to constructor. The following line creates a matrix from a given table of numbers. The number of elements in a table should be greater or equal to the number of coefficients in created matrix. The table should contain rows of the matrix.
When one needs to create an array of matrices which have undefined size at compilation time, the following solution is available.
which means that tab contains an adress of a table of 10 matrices, each of size 2x4. When the same method is applied to the matrices of fixed dimensions, there will be no effect
The pointer tab2 contains the address of a table of 10 matrices each of size 4x4 (the parameters 5,6 are ingorred because type DMatrix4D has fixed size).
Indexing
One can change or access a coefficient in a matrix by using operator() or iterators. The operator() has two arguments - number of row and number of column of the coefficient that is to be accessed. Rows and columns are numbered from 1 to the number of rows and the number of columns, respectively. See an example below.
The rows and columns of a matrix can be seen as vectors. The vectalg module provides two classes: RowVector and ColumnVector that can be used as references to rows and columns of matrices. Objects of these classes don't have their own allocated memory but only a pointer to a proper coefficient in a matrix.
These classes have almost the same properties as class Vector (indexing, iterators, normalization), hence they can be used as vectors in generic algorithms. Objects of these classes are created by methods of class Matrix
Rows and columns of a matrix are indexed from zero to number of rows minus 1 and number of columns minus 1, respectively. Class Martix defines two special types for references to rows and columns
which are useful when one needs to perform many operations on fixed row or column.
The class Matrix provides low level iterators to a container which stores all the coefficients. They are useful when one needs to perform some operation on each element of a matrix, as in the Hadamard product of two matrices. The following code implements operation Q = Q*P, where symbol '*' denotes the Hadamard product.
Functions begin and end return low level iterators for the container of a matrix.
Const iterators for constant objects are defined in a similar way. An example below computes sum of all numbers in a matrix P
One can use in generic algorithms types MatrixIterator and const_MatrixIterator for manipulating on coefficients in a matrix. These iterators are returned by functions beginMatrix, endMatrix, beginOfRow, endOfRow, beginOfColumn, endOfColumn
The following member functions are available for moving those iterators
One can access a coefficient pointed by iterator by using operator*
For more details about MatrixIterator and const_MatrixIterator see the header file "capd/vectalg/MatrixIterator.h".
The following operations on matrices and vectors are available
Moreover, the standard operations like +=, -= etc. whenever possible are available
Transpose - if Q is a square matrix, it can be transposed by calling
clear - this member function assigns zero to each coefficient in the matrix
Identity - this static function returns the identity matrix of a given dimension
The following operations are available for interval matrices only - compare similar methods for the class Vector