Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

IncMatrix - MetaTrader 5 Library | MT5 EA Download - MetaTrader 5 Resources

author EAcpu | 2 reads | 0 comments |

Class for working with matrices.

Matrices are created as one-dimensional arrays, with elements in the order: first row, second row, etc. The last two elements represent the size of the matrix: the number of columns and the number of rows.

 Double m[]={ 1 , 2 , 3 ,
4 , 5 , 6 ,
2 , 3 }; // A matrix with two rows and three columns.

Class methods:

Blank setting size (
Double &aA[],
Integers in a row,
integer column)

Set the size of matrix aA. aRows - number of rows, aCols - number of columns.

Blank setting value (
Double &aA[],
One line of integers ,
integer col,
double the value)

Set the value (Value) of the matrix (aA) element located at row aRow and column aCol.

integer getsize(
Double &aA[],
integer & row,
integer &a column)

Returns the number of elements of matrix aA. Returned by reference: aRows - number of rows, aCols - number of columns.

integer get row(
Double &aA[]
)

Returns the number of rows in matrix aA.

integer get column (
Double &aA[]
)

Returns the number of columns in matrix aA.

Double the value obtained (
Double &aA[],
One line of integers ,
integer col)

Gets the value of the element in matrix aA at row aRow and column aCol.

blank copy (
Double & aFrom[],
Double &aTo[]
)

Copies the matrix from array aFrom to array aTo.

Boolean check added (
Double &aA[],
Double &aB[]
)

Check if the added sizes of the two matrices match (height and width are exactly equal).

boolean check for multiple values ​​(
Double &aA[],
Double &aB[]
)

Check that the multiplicative sizes of the two matrices match (the number of columns in matrix aA equals the number of columns in matrix aB).

Boolean checkIsSq(
Double &aA[]
)

Check if the matrix is ​​a square matrix.

Blank plus sign (
Double &aA[],
Double a number,
Double &aR[]
)

Add the number aNum to the matrix aA. The resulting matrix is ​​returned by reference in the array aR.

blank majority(
Double &aA[],
Double a number,
Double &aR[]
)

Multiply the matrix aA by the number aNum. The resulting matrix is ​​returned by reference in the array aR.

Blank add Mx(
Double &aA[],
Double &aB[],
Double &aAB[]
)

Add matrix aA to matrix aB. The resulting matrix is ​​returned by reference in the array aAB.

Blank MultiMx(
Double &aA[],
Double &aB[],
Double &aAB[])

Multiply matrix aA by matrix aB. The resulting matrix is ​​returned by reference in the array aAB.

Blank Transpose (
Double &aA[],
double & in []
)

Transpose matrix aA. The transposed matrix is ​​returned by reference in the array aT.

Blank Algega (
Double &aA[],
Double &aAA[]
)

Get the cofactor matrix. aA - source matrix, aAA - cofactor (returned by reference).

boolean inversion (
Double &aA[],
Double &aB[]
)

Returns the inverse matrix aR of matrix aA by reference. This method returns true if the inverse matrix exists; false if the inverse matrix does not exist.

blank triangle (
Double &aA[],
double & in []
)

Returns the triangular matrix aT from the matrix aA by reference.

blank minor (
Double an A[],
One line of integers ,
integer col,
Double & is []
)

Gets the decimal fraction of matrix aA by row aRow and column aCol. Minor is returned by reference in the array aM.

Double secondary defense (
Double &aA[],
One line of integers ,
integer col)

Returns the determinant value of row aRow and column aCol of matrix aA.

BlankMinorDefMx (
Double &aA[],
Double & is []
)

Gets the secondary matrix (the matrix with secondary determinant values). aA - source matrix, aM - matrix with minor determinant (returned by reference).

The definition of double (
Double &aA[]
)

Returns the determinant value of matrix aA.

integer rank (
Double &aA[]
)

Returns the rank of matrix aA.

Integer ranking DRC(
Double &aA[],
Double &aDef,
integer & row,
Integer &aCol
)

Returns the rank of matrix aA by reference:

Blank Copy Column (
Double & aFrom[],
Double & aTo[],
integer aFromCol,
integer aToCol,
Double &aR[]
)

Copies the column at index aFromCol from matrix aFrom to matrix aTo to the column at index aToCol. The result is returned by reference in the array aR.

Blank copy line(
Double & aFrom[],
Double & aTo[],
integer aFromRow,
integer row,
Double &aR[]
)

Copies the row at index aFromRow from matrix aFrom to matrix aTo to the row at index aToRow. The result is returned by reference in the array aR.

Blank Append Column(
Double &aA[],
Double &aC[],
Double &aF[]
)

Extend matrix aA by adding column aC to matrix aA. The result is returned by reference in the array aF.

Blank Append Line (
Double &aA[],
Double &aR[],
Double &aF[]
)

Extend matrix aA by adding row aR to matrix aA. The result is returned by reference in the array aF.

boolean system Kramer (
Double &aK[],
Double &aY[],
Double &aX[]
)

Use Cramer's rule to solve systems of linear equations.

Boolean system inverse (
Double &aK[],
Double &aY[],
Double &aX[]
)

Solve systems of linear equations using invertible matrices.

Boolean system Gaussian (
Double &aK[],
Double &aY[],
Double &aX[]
)

Solve systems of linear equations using Gaussian elimination.

Integer system check(
Double &aK[],
Double &aY[]
)

Check the system of equations.

Return value:

blank alert(
Double &aA[],
Integer a number = 2,
string title= ””
)

Display the entire matrix in an alert box.

Blank Alert 2 (
Double &aA[],
Integer a number = 2,
string title= ””
)

Showing the matrix row by row in the alert box, showing the rows from bottom to top, then showing the header, i.e. the orientation of the matrix in the alert box is normal: the header is on top, then the rows are shown sequentially.

BlankAlert1Str (
Double &aA[],
Integer a number = 2
)

Display matrix array as 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 matrices, and Gaussian elimination.


Attachment download

📎 incmatrix.mqh (29.22 KB)

📎 smatrix.mq5 (2.18 KB)

Source: MQL5 #951

Verification code Refresh