Class for working with matrices.
Matrix is created in one dimensional array, in sequence: elements of first row, second and so on. The last two elements represent the size of matrix: number of columns and rows.
Example:
double m[]={1,2,3, Â Â Â Â Â Â Â Â Â Â 4,5,6, Â Â Â Â Â Â Â Â Â Â 2,3}; // Matrix of two rows and three columns.
Class methods:
Method | Description of method and parameters |
---|---|
void SetSize( |
Sets the size of matrix aA. aRows – number of rows, aCols – number of columns. |
void SetValue( |
Sets the value (Value) of matrix (aA) element located in row aRow, column aCol. |
int GetSize( |
Returns the number of matrix aA elements. By reference returns: aRows – number of rows, aCols – number of columns. |
int GetRows( |
Returns the number of rows in matrix aA. |
int GetCols( |
Returns the number of columns in matrix aA. |
double GetValue( |
Gets the value of element in matrix aA located in row aRow and column aCol. |
void Copy( |
Copies matrix from array aFrom to array aTo. |
bool CheckForAdd( |
Checks if two matrices match by size for addition (fully equivalent by height and width). |
bool CheckForMult( |
Checks if two matrices match by size for multiplication (number of columns in matrix aA equals the number of columns in matrix aB). |
bool CheckIsSq( |
Checks if matrix is square. |
void AddNum( |
Adds number aNum to matrix aA. Resulting matrix is returned by reference in array aR. |
void MultNum( |
Multiplies matrix aA by number aNum. Resulting matrix is returned by reference in array aR. |
void AddMx( |
Adds matrix aA to matrix aB. Resulting matrix is returned by reference in array aAB. |
void MultMx( |
Multiplies matrix aA by matrix aB. Resulting matrix is returned by reference in array aAB. |
void Transpose( |
Transposes matrix aA. Transposed matrix is returned by reference in array aT. |
void AlgAdd( |
Gets cofactor matrix. aA – source matrix, aAA – cofactor (returned by reference). |
bool Invert( |
Returns the inverse matrix aR of matrix aA by reference. The method returns true if inverse matrix exists or false, if inverse matrix does not exist. |
void Triangle( |
Returns triangular matrix aT from matrix aA by reference. |
void Minor( |
Gets the minor of matrix aA by row aRow and column aCol. Minor is returned by reference in array aM. |
double MinorDef( |
Returns the determinant value of the matrix aA minor by row aRow and column aCol. |
void MinorDefMx( |
Gets minors matrix (matrix with values of the minors determinants). aA – source matrix, aM – matrix with minors determinants (returned by reference). |
double Def( |
Returns the determinant value of matrix aA. |
int Rank( |
Returns rank of matrix aA. |
int RankDRC( |
Returns rank of matrix aA and by reference returns:
|
void CopyCol( |
Copies column with index aFromCol from matrix aFrom to matrix aTo to column with index aToCol. Result is returned by reference in array aR. |
void CopyRow( |
Copies row with index aFromRow from matrix aFrom to matrix aTo to row with index aToRow. Result is returned by reference in array aR. |
void AppendCol( |
Extends matrix aA by adding column aC to it. Result is returned by reference in array aF. |
void AppendRow( |
Extends matrix aA by adding row aR to it. Result is returned by reference in array aF. |
bool SystemKramer( |
Solves system of linear equations using Cramer’s rule.
|
bool SystemInverse( |
Solves system of linear equations using invertible matrix.
|
bool SystemGauss( |
Solves system of linear equations using Gaussian elimination.
|
int SystemCheck( |
Checks system of equations.
Returned value:
|
void Alert( |
Displays the entire matrix in one alert box.
|
void Alert2( |
Displays matrix in alert box line by line, rows displayed from bottom to top, then title, i.e. in alert box matrix is oriented normally: title at the top, then rows in order. |
void Alert1Str( |
Displays array of matrix as a string in alert box. |
Â
The sMatrix.mq4 script is an example of using this library to solve a system of linear equations using Cramer’s rule, invertible matrix and Gaussian elimination.