Matrix class. More...
#include <mi32/mimatrix.h>
Public Member Functions | |
| MIMATRIX (const MIMATRIX &rhs) | |
| MIMATRIX () | |
| ~MIMATRIX () | |
| ERRVALUE | Add (const MIMATRIX &matrix) |
| void | Add (UINT32 row, UINT32 col, double value) |
| void | AddScalar (double value) |
| double | ComputeConditionNumber () const |
| double | ComputeDeterminant () const |
| ERRVALUE | ComputeEigen (MIMATRIX &EigenVectors, MIMATRIX &EigenValues) const |
| ERRVALUE | ComputeInverse (MIMATRIX &result, UINT32 MaxIterations=0, double MaxError=0) const |
| double | ComputeMaxAbsolute () const |
| ERRVALUE | ComputePseudoInverse (MIMATRIX &result, double tolerance=0) const |
| ERRVALUE | ComputeSVD (MIMATRIX &U, MIMATRIX &W, MIMATRIX &V) const |
| double | ComputeTrace () const |
| ERRVALUE | Create (UINT32 Rows, UINT32 Cols, const double *values=0) |
| ERRVALUE | CreateDiagonal (const MIMATRIX &vector) |
| ERRVALUE | CreateDiagonal (UINT32 Size, double value) |
| ERRVALUE | CreateProduct (const MIMATRIX &left, const MIMATRIX &right) |
| ERRVALUE | GetDiagonal (MIMATRIX &result) const |
| UINT32 | GetNumColumns () const |
| UINT32 | GetNumElements () const |
| UINT32 | GetNumRows () const |
| double | GetValueFast (UINT32 num) const |
| double | GetValueFast (UINT32 row, UINT32 col) const |
| void | GetValues (double *values) const |
| double | GetValueValidated (UINT32 num) const |
| double | GetValueValidated (UINT32 row, UINT32 col) const |
| bool | IsDiagonal (double tolerance=0) const |
| bool | IsEqual (const MIMATRIX &matrix, double tolerance=0) const |
| bool | IsSameSize (const MIMATRIX &matrix) const |
| bool | IsSingular () const |
| bool | IsSymmetric (double tolerance=0) const |
| bool | IsVector () const |
| ERRVALUE | MultiplyLeft (const MIMATRIX &left) |
| ERRVALUE | MultiplyRight (const MIMATRIX &right) |
| void | MultiplyScalar (double value) |
| MIMATRIX & | operator*= (double value) |
| const MIMATRIX | operator- () |
| MIMATRIX & | operator/= (double value) |
| MIMATRIX & | operator= (const MIMATRIX &rhs) |
| ERRVALUE | ReplaceSubMatrix (UINT32 TgtStartRow, UINT32 TgtStartCol, const MIMATRIX &SrcMatrix, UINT32 SrcStartRow=0, UINT32 SrcStartCol=0, UINT32 NumRows=0, UINT32 NumCols=0) |
| ERRVALUE | Resize (UINT32 Rows, UINT32 Cols) |
| void | RotateClockwise () |
| void | SetIdentity () |
| void | SetScalar (double value) |
| void | SetValueFast (UINT32 num, double value) |
| void | SetValueFast (UINT32 row, UINT32 col, double value) |
| void | SetValueValidated (UINT32 num, double value) |
| void | SetValueValidated (UINT32 row, UINT32 col, double value) |
| void | SetZero () |
| ERRVALUE | SolveLinear (const MIMATRIX &A, const MIMATRIX &B, double tolerance=0) |
| ERRVALUE | SolveLinearSVD (const MIMATRIX &U, const MIMATRIX &W, const MIMATRIX &V, const MIMATRIX &B, double tolerance=0) |
| ERRVALUE | Subtract (const MIMATRIX &matrix) |
| void | Swap (MIMATRIX &other) |
| void | Transpose () |
Matrix class.
| MIMATRIX::MIMATRIX | ( | ) |
Default constructor.
| MIMATRIX::MIMATRIX | ( | const MIMATRIX & | rhs | ) |
Copy constructor.
| MIMATRIX::~MIMATRIX | ( | ) |
Destructor.
Add matrix.
Matrix to be added must be same size as this matrix.
| void MIMATRIX::AddScalar | ( | double | value | ) |
Add scalar value to all elements in matrix.
| double MIMATRIX::ComputeConditionNumber | ( | ) | const |
Compute "condition number" of matrix.
The condition number of a matrix is defined as the ratio of the largest (in magnitude) of the elements of matrix W to the smallest one. Where W is one of the results of SVD defined as: T A = U * W * V (see ComputeSVD). A matrix is singular if it's condition number is large.
| double MIMATRIX::ComputeDeterminant | ( | ) | const |
Compute determinant.
Compute Eigenvectors and Eigenvalues from symmetric matrix.
Matrix must be symmetric, error will be returned if not.
| EigenVectors | Eigenvectors returned as columns | |
| EigenValues | Eigenvalues returned |
| ERRVALUE MIMATRIX::ComputeInverse | ( | MIMATRIX & | result, | |
| UINT32 | MaxIterations = 0, |
|||
| double | MaxError = 0 | |||
| ) | const |
Compute inverse of square matrix.
| result | Result matrix | |
| MaxIterations | Maximum number of iterations |
| double MIMATRIX::ComputeMaxAbsolute | ( | ) | const |
Compute maximum absolute element value.
Compute pseudoinverse of matrix using SVD.
If Input matrix is not singular pseudoinverse is equal to normal inverse of the matrix. Pseudoinverse is such matrix X that satisfy the following condition: A * X * A = A, if matrix A is singular X still exists.
| result | Result matrix | |
| tolerance | Tolerance to use, 0 for default |
Compute Singular Value Decomposition (SVD).
This function computes SVD as A(MxN) = U(MxN) * W(N) * V(NxN)[transpose] ; Output matrix U has the same dimension as input matrix A and the columns will be the orthonormal basis vectors for A. The diagonal matrix of singular values W is output as a vector. The matrix V (not transpose of V) is output as a matrix.
| W | Returned | |
| V | Returned Returned |
| double MIMATRIX::ComputeTrace | ( | ) | const |
Compute trace (sum of diagonal elements).
Create matrix of specified size.
| Rows | Number of rows | |
| Cols | Number of columns | |
| values | Initial values as Rows * Cols array |
Create diagonal matrix from vector.
Will create a square matrix of order N + ABS(K) with elements of input on the K-th diagonal. K = 0 is the main diagonal, K > 0 is above main diagonal, K < 0 below.
| vector | One-dimensional matrix containing diagonal values |
Create diagonal matrix of specified size.
| Size | Size of matrix to create | |
| value | Value to replicate on diagonal |
Create matrix as product of two matrices.
| left | Left side of multiplication | |
| right | Right side of multiplication |
Get diagonal elements as column vector.
| result | Column vector returned |
| UINT32 MIMATRIX::GetNumColumns | ( | ) | const [inline] |
Get number of columns in matrix.
| UINT32 MIMATRIX::GetNumElements | ( | ) | const [inline] |
Get number of matrix elements.
| UINT32 MIMATRIX::GetNumRows | ( | ) | const [inline] |
Get number of rows in matrix.
| double MIMATRIX::GetValueFast | ( | UINT32 | num | ) | const [inline] |
Get vector value at location with no validation.
Intended for use on 'vector' matrix (1 x N or N x 1) only.
| num | Vector element number |
Get value at location with no validation.
| row | Row (0-based) | |
| col | Column (0-based) |
| void MIMATRIX::GetValues | ( | double * | values | ) | const |
Get values as array.
| values | Values returned, must be large enough to hold all elements |
| double MIMATRIX::GetValueValidated | ( | UINT32 | num | ) | const |
Get vector value at location with validation of element location.
Intended for use on 'vector' matrix (1 x N or N x 1) only.
| num | Vector element number |
Get value at location with validation of element location.
| row | Row (0-based) | |
| col | Column (0-based) |
| bool MIMATRIX::IsDiagonal | ( | double | tolerance = 0 |
) | const |
Determine if matrix has at one non-zero element on main diagonal and zero everywhere else.
| bool MIMATRIX::IsEqual | ( | const MIMATRIX & | matrix, | |
| double | tolerance = 0 | |||
| ) | const |
Determine if matrices are equal within specified tolerance.
Will return false if matrices are not the same size.
| bool MIMATRIX::IsSameSize | ( | const MIMATRIX & | matrix | ) | const [inline] |
Determine if matrices are the same size.
| bool MIMATRIX::IsSingular | ( | ) | const |
Determine if matrix is singular.
Uses ComputeConditionNumber with default limits. This is not a fast operation.
| bool MIMATRIX::IsSymmetric | ( | double | tolerance = 0 |
) | const |
Determine if matrix is symmetric.
| bool MIMATRIX::IsVector | ( | ) | const [inline] |
Determine if matrix is a 'vector' (1 x N or N x 1 matrix).
| void MIMATRIX::MultiplyScalar | ( | double | value | ) |
Multiply all matrix elements by specified value.
| MIMATRIX& MIMATRIX::operator*= | ( | double | value | ) | [inline] |
Multiply by scalar.
| const MIMATRIX MIMATRIX::operator- | ( | ) | [inline] |
Negation.
| MIMATRIX& MIMATRIX::operator/= | ( | double | value | ) | [inline] |
Divide by scalar.
| ERRVALUE MIMATRIX::ReplaceSubMatrix | ( | UINT32 | TgtStartRow, | |
| UINT32 | TgtStartCol, | |||
| const MIMATRIX & | SrcMatrix, | |||
| UINT32 | SrcStartRow = 0, |
|||
| UINT32 | SrcStartCol = 0, |
|||
| UINT32 | NumRows = 0, |
|||
| UINT32 | NumCols = 0 | |||
| ) |
Replace elements with submatrix of elements from another matrix.
| TgtStartCol | Target matrix starting row | |
| SrcMatrix | Target matrix starting column | |
| SrcStartRow | Source matrix | |
| SrcStartCol | Source matrix starting row | |
| NumRows | Source matrix starting column | |
| NumCols | Number of rows to replace, 0 for maximum possible Number of columns to replace, 0 for maximum possible |
Resize matrix.
Newly created elements will be initialized to 0.
| void MIMATRIX::RotateClockwise | ( | ) |
Rotate the matrix 90 degrees clockwise If tha matrix is not square, it will be resized (i.e., an NxM matrix will become an MxN matrix.
| void MIMATRIX::SetIdentity | ( | ) |
Set matrix to identity.
| void MIMATRIX::SetScalar | ( | double | value | ) |
Set all elements in matrix to a specified scalar value.
| void MIMATRIX::SetValueFast | ( | UINT32 | num, | |
| double | value | |||
| ) | [inline] |
Set vector value at location with no validation.
Intended for use on 'vector' matrix (1 x N or N x 1) only.
| value | Vector element number |
Set value at location with no validation.
| void MIMATRIX::SetValueValidated | ( | UINT32 | num, | |
| double | value | |||
| ) |
Set vector value at location with validation of element location.
Intended for use on 'vector' matrix (1 x N or N x 1) only.
| value | Vector element number |
Set value at location with validation of element location.
| void MIMATRIX::SetZero | ( | ) | [inline] |
Set all matrix elements to zero.
Solve system of linear equations and put result in this matrix.
A * X = B where A(M x N) matrix and X (N) vector. B(M) is also a vector. This is done using ComputeSVD, if already have performed SVD then can use SolveLinearSVD for improved performance.
| A | M x N matrix of linear equations | |
| B | Vector of linear equation values | |
| tolerance | Tolerance, 0 to use default based on maximum value in SVD W matrix |
| ERRVALUE MIMATRIX::SolveLinearSVD | ( | const MIMATRIX & | U, | |
| const MIMATRIX & | W, | |||
| const MIMATRIX & | V, | |||
| const MIMATRIX & | B, | |||
| double | tolerance = 0 | |||
| ) |
Solve system of linear equations using SVD components.
| U | From ComputeSVD | |
| W | From ComputeSVD | |
| V | From ComputeSVD | |
| tolerance | Tolerance, 0 to use default based on maximum value in SVD W matrix |
Subtract matrix.
Matrix to be subtracted must be same size as this matrix.
| void MIMATRIX::Swap | ( | MIMATRIX & | other | ) |
Swap this matrix with another.
This is done by swapping memory pointers so is very fast.
| other | Matrix to swap with |
| void MIMATRIX::Transpose | ( | ) |
Transpose matrix.
1.6.1