Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

otMatrix Class Reference
[Matrix libraryMatrix library]

Matrix library.

#include <otMatrix.h>


Public Types

enum  InitZero { InitMatWithZero, NoInitMatZero }

Public Member Functions

 otMatrix ()
 otMatrix (const S16 _i16row, const S16 _i16col, InitZero _init=InitMatWithZero)
 otMatrix (const S16 _i16row, const S16 _i16col, F32 *initData)
void create (const S16 _i16row, const S16 _i16col, InitZero _init=InitMatWithZero)
void create (const S16 _i16row, const S16 _i16col, F32 *initData)
Proxy operator[] (S16 _row)
void close ()
bool isValid ()
bool isSquare ()
S16 getRow ()
S16 getCol ()
bool operator== (otMatrix _compare)
otMatrix operator+ (otMatrix _matAdd)
otMatrix operator- (otMatrix _matSub)
otMatrix operator- (void)
otMatrix operator * (otMatrix _matMul)
otMatrix operator= (otMatrix _mat)
void vSetHomogen (const F32 _val)
void vRoundingElementToZero (const S16 _i, const S16 _j)
otMatrix RoundingMatrixToZero ()
void vSetToZero ()
void vSetRandom (const S32 _maxRand, const S32 _minRand)
void vSetDiag (const F32 _val)
void vSetIdentity ()
void Copy (otMatrix &_outp)
otMatrix InsertVector (otMatrix _Vector, const S16 _posColumn)
otMatrix InsertSubMatrix (otMatrix _subMatrix, const S16 _posRow, const S16 _posColumn)
otMatrix InsertSubMatrix (otMatrix _subMatrix, const S16 _posRow, const S16 _posColumn, const S16 _lenRow, const S16 _lenColumn)
otMatrix InsertSubMatrix (otMatrix _subMatrix, const S16 _posRow, const S16 _posColumn, const S16 _posRowSub, const S16 _posColumnSub, const S16 _lenRow, const S16 _lenColumn)
otMatrix Transpose ()
bool bNormVector ()
otMatrix Invers ()
bool bMatrixIsPositiveDefinite (bool checkPosSemidefinite=false)
otMatrix GetDiagonalEntries (void)
otMatrix CholeskyDec ()
otMatrix HouseholderTransformQR (const S16 _rowTransform, const S16 _columnTransform)
bool QRDec (otMatrix &Qt, otMatrix &R)
otMatrix BackSubtitution (otMatrix &A, otMatrix &B)
otMatrix ForwardSubtitution (otMatrix &A, otMatrix &B)

Static Public Member Functions

static void garbageClean (U32 start=0)
static void addGarbage (otMatrix *mat)
static U32 garbageCount ()

Data Structures

class  Proxy


Member Enumeration Documentation

enum otMatrix::InitZero
 

Enumeration values:
InitMatWithZero  Initialize matrix with zero.
NoInitMatZero  Don't init.


Constructor & Destructor Documentation

otMatrix.otMatrix  ) 
 

Create the class

otMatrix.otMatrix const S16  _i16row,
const S16  _i16col,
InitZero  _init = InitMatWithZero
 

Create and init the matrix

Parameters:
_i16row Number of rows
_i16col Number of columns
_init Init mode

otMatrix.otMatrix const S16  _i16row,
const S16  _i16col,
F32 initData
 

Create and init the matrix

Parameters:
_i16row Number of rows
_i16col Number of columns
initData Array of data to set initial value. Must be _i16row * _i16col size.


Member Function Documentation

static void otMatrix.addGarbage otMatrix mat  )  [static]
 

otMatrix otMatrix.BackSubtitution otMatrix A,
otMatrix B
 

Do the back-subtitution operation for upper triangular matrix A & column matrix B to solve x:
Ax = B

 x = BackSubtitution(A, B);
WARNING! To lower the computation cost, we don't check that A is a upper triangular matrix (it's assumed that user already make sure before calling this routine).
Parameters:
A Upper triangular matrix
B Column matrix
Returns:
Solved matrix

bool otMatrix.bMatrixIsPositiveDefinite bool  checkPosSemidefinite = false  ) 
 

Use elemtary row operation to reduce the matrix into upper triangular form (like in the first phase of gauss-jordan algorithm). Useful if we want to check the matrix as positive definite or not (can be used before calling CholeskyDec function).

Parameters:
checkPosSemidefinite Specify what return
Returns:
False if less than 0+ (zero included) when checkPosSemidefinite is false, False if less than 0- (zero is not included) when checkPosSemidefinite is true.

bool otMatrix.bNormVector  ) 
 

Normalize the vector

Returns:
True on success

otMatrix otMatrix.CholeskyDec  ) 
 

Do the Cholesky Decomposition using Cholesky-Crout algorithm.

 A = L * L'     ; A = real, positive definite, and symmetry MxM matrix

 L = A.CholeskyDec();
WARNING! The symmetry property is not checked at the beginning to lower the computation cost. The processing is being done on the lower triangular component of _A. Then it is assumed the upper triangular is inherently equal to the lower end. (as a side note, Scilab & MATLAB is using Lapack routines DPOTRF that process the upper triangular of _A. The result should be equal mathematically if A is symmetry).
Returns:
Decomposed matrix

void otMatrix.close  ) 
 

Free all allocated memory and set the matrix as invalid. Use this function only for dynamic allocation when the matrix is greather then 6x6

void otMatrix.Copy otMatrix _outp  ) 
 

Copy this matrix content to a destination matrix. Matrix size must be the same.

Parameters:
_outp Destination matrix

void otMatrix.create const S16  _i16row,
const S16  _i16col,
F32 initData
 

Create and init the matrix

Parameters:
_i16row Number of rows
_i16col Number of columns
initData Array of data to set initial value. Must be _i16row * _i16col size.

void otMatrix.create const S16  _i16row,
const S16  _i16col,
InitZero  _init = InitMatWithZero
 

Create and init the matrix

Parameters:
_i16row Number of rows
_i16col Number of columns
_init Init mode

otMatrix otMatrix.ForwardSubtitution otMatrix A,
otMatrix B
 

Perform forward-substitution operations on triangular matrix A & matrix column B.
Ax = B

To save computation, matrix A is not done triangular checking (assumed to be lower-triangular).

Parameters:
A Upper triangular matrix
B Column matrix
Returns:
Solved matrix

static void otMatrix.garbageClean U32  start = 0  )  [static]
 

C++ overloading produces several intermediate classes that are allocated in memory but not reachable. This is the only way to free the memory of all these unreachable objects. Run this function at the end of matrix process. Use this function only for dynamic allocation when the matrix is greather then 6x6

static U32 otMatrix.garbageCount  )  [static]
 

S16 otMatrix.getCol  ) 
 

Read number of matrix columns

Returns:
Number of columns

otMatrix otMatrix.GetDiagonalEntries void   ) 
 

For square matrix 'this' with size MxM, return vector Mx1 with entries corresponding with diagonal entries of 'this'.

     *  Example:    this = [a11 a12 a13]
     *                     [a21 a22 a23]
     *                     [a31 a32 a33]
     * 
     * out = this.GetDiagonalEntries() = [a11]
     *                                   [a22]
     *                                   [a33]
	 * 
Returns:
Matrix diagonal

S16 otMatrix.getRow  ) 
 

Read number of matrix rows

Returns:
Number of rows

otMatrix otMatrix.HouseholderTransformQR const S16  _rowTransform,
const S16  _columnTransform
 

Do the Householder Transformation for QR Decomposition operation.

Parameters:
_rowTransform Start row
_columnTransform Start column
Returns:
Transformed matrix

otMatrix otMatrix.InsertSubMatrix otMatrix  _subMatrix,
const S16  _posRow,
const S16  _posColumn,
const S16  _posRowSub,
const S16  _posColumnSub,
const S16  _lenRow,
const S16  _lenColumn
 

Insert the _lenRow & _lenColumn submatrix, start from _posRowSub & _posColumnSub submatrix; into matrix at the matrix's _posRow and _posColumn position.

     * Example: A = Matrix 4x4, B = Matrix 2x3
     *
     *  C = A.InsertSubMatrix(B, 1, 1, 0, 1, 1, 2);
     *
     *  A = [A00  A01  A02  A03]    B = [B00  B01  B02]
     *      [A10  A11  A12  A13]        [B10  B11  B12]
     *      [A20  A21  A22  A23]
     *      [A30  A31  A32  A33]
     *
     *
     *  C = [A00  A01  A02  A03]
     *      [A10  B01  B02  A13]
     *      [A20  A21  A22  A23]
     *      [A30  A31  A32  A33]
	 * 
Parameters:
_subMatrix Matrix to be insert
_posRow Destination row
_posColumn Destination columns
_posRowSub Row of the matrix to insert
_posColumnSub Column of the matrix to insert
_lenRow Number of rows to insert
_lenColumn Number of columns to insert
Returns:
Modified matrix

otMatrix otMatrix.InsertSubMatrix otMatrix  _subMatrix,
const S16  _posRow,
const S16  _posColumn,
const S16  _lenRow,
const S16  _lenColumn
 

Insert the first _lenRow-th and first _lenColumn-th submatrix into matrix; at the matrix's _posRow and _posColumn position.

     * Example: A = Matrix 4x4, B = Matrix 2x3
     *  C = A.InsertSubMatrix(B, 1, 1, 2, 2);
     *
     *  A = [A00  A01  A02  A03]    B = [B00  B01  B02]
     *      [A10  A11  A12  A13]        [B10  B11  B12]
     *      [A20  A21  A22  A23]
     *      [A30  A31  A32  A33]
     *
     *
     *  C = [A00  A01  A02  A03]
     *      [A10  B00  B01  A13]
     *      [A20  B10  B11  A23]
     *      [A30  A31  A32  A33]
	 * 
Parameters:
_subMatrix Matrix to be insert
_posRow Destination row
_posColumn Destination columns
_lenRow Number of rows to insert
_lenColumn Number of columns to insert
Returns:
Modified matrix

otMatrix otMatrix.InsertSubMatrix otMatrix  _subMatrix,
const S16  _posRow,
const S16  _posColumn
 

Insert submatrix into matrix at _posRow & _posColumn position

     * Example: A = Matrix 4x4, B = Matrix 2x3
     *
     *  C = A.InsertSubMatrix(B, 1, 1);
     *
     *  A = [A00  A01  A02  A03]    B = [B00  B01  B02]
     *      [A10  A11  A12  A13]        [B10  B11  B12]
     *      [A20  A21  A22  A23]
     *      [A30  A31  A32  A33]
     *
     *
     *  C = [A00  A01  A02  A03]
     *      [A10  B00  B01  B02]
     *      [A20  B10  B11  B12]
     *      [A30  A31  A32  A33]
	 * 
Parameters:
_subMatrix Matrix to be insert
_posRow Row of the insertion
_posColumn Column of the insertion
Returns:
Modified matrix

otMatrix otMatrix.InsertVector otMatrix  _Vector,
const S16  _posColumn
 

Insert vector into matrix at _posColumn position

     * Example: A = Matrix 3x3, B = Vector 3x1
     *
     *  C = A.InsertVector(B, 1);
     *
     *  A = [A00  A01  A02]     B = [B00]
     *      [A10  A11  A12]         [B10]
     *      [A20  A21  A22]         [B20]
     *
     *  C = [A00  B00  A02]
     *      [A10  B10  A12]
     *      [A20  B20  A22]
	 * 
Parameters:
_Vector Vector (as matrix) to be inserted
_posColumn Column where to insert
Returns:
Modified matrix

otMatrix otMatrix.Invers  ) 
 

Invers operation using Gauss-Jordan algorithm.

Returns:
Matrix after inversion, if possible. Check if valid or not.

bool otMatrix.isSquare  ) 
 

Check if the matrix is square

Returns:
True if the matrix is square

bool otMatrix.isValid  ) 
 

Check if the matrix is valid or not

Returns:
True for valid matrix

otMatrix otMatrix.operator * otMatrix  _matMul  ) 
 

C++ overloading for matrix multiply

otMatrix otMatrix.operator+ otMatrix  _matAdd  ) 
 

C++ overloading for matrix add

otMatrix otMatrix.operator- void   ) 
 

C++ overloading for matrix unary operation

otMatrix otMatrix.operator- otMatrix  _matSub  ) 
 

C++ overloading for matrix subtract

otMatrix otMatrix.operator= otMatrix  _mat  ) 
 

C++ overloading for matrix assign

bool otMatrix.operator== otMatrix  _compare  ) 
 

C++ overloading for matrix compare

Proxy otMatrix.operator[] S16  _row  ) 
 

bool otMatrix.QRDec otMatrix Qt,
otMatrix R
 

Do the QR Decomposition for matrix using Householder Transformation.
A = Q * R

WARNING! The matrix calculated by this function return Q' and R (Q transpose and R). Because QR Decomposition usually used to calculate solution for least-squares equation (that need Q'), we don't do the transpose of Q inside this routine to lower the computation cost).

     * Example of using QRDec to solve least-squares:
     *                      Ax = b
     *                   (QR)x = b
     *                      Rx = Q'b    --> Afterward use back-subtitution to solve x
	 * 
Parameters:
Qt Output matrix
R Output matrix
Returns:
True on success

otMatrix otMatrix.RoundingMatrixToZero  ) 
 

Round all matrix to 0

otMatrix otMatrix.Transpose  ) 
 

Return the transpose of the matrix. Reverse rows with columns.

Returns:
Transposed matrix

void otMatrix.vRoundingElementToZero const S16  _i,
const S16  _j
 

Round to 0 specified matrix location

void otMatrix.vSetDiag const F32  _val  ) 
 

Set diagonal matrix at specified value and clear the rest

Parameters:
_val Diagonal value

void otMatrix.vSetHomogen const F32  _val  ) 
 

Set initial value for all matrix contents

void otMatrix.vSetIdentity  ) 
 

Set as unitary matrix. Same as vSetHomogen(1.0)

void otMatrix.vSetRandom const S32  _maxRand,
const S32  _minRand
 

Set all matrix to random value

Parameters:
_maxRand Maximum value
_minRand Minimum value

void otMatrix.vSetToZero  ) 
 

Set all matrix to 0. Same as vSetHomogen(0.0)


The documentation for this class was generated from the following file: footer
otStudio - Library Reference - (C) 2020-23 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0