The MatMul method, which enables the multiplication of matrices and vectors, has several overloads.
Multiplying a matrix by a matrix: matrix[M][K] * matrix[K][N] = matrix[M][N]
Multiplying a vector by a matrix: horizontal vector[K] * matrix[K][N] = horizontal vector[N]
Multiplying a matrix by a vector: matrix[M][K] * vertical vector[K] = vertical vector[M]
Scalar vector multiplication: horizontal vector * vertical vector = dot value
[in] Matrix or vector.
Matrix, vector, or scalar, depending on the method used.
The matrices should be compatible for multiplication, i.e. the number of columns in the first matrix should be equal to the number of rows in the second matrix. Matrix multiplication is non-commutative: the result of multiplying the first matrix by the second one is not equal to the result of multiplying the second matrix by the first one in the general case.
The matrix product consists of all possible combinations of scalar products of the row vectors of the first matrix and the column vectors of the second matrix.
In scalar multiplication, vectors must have the same length.
When multiplying a vector and a matrix, the length of the vector must exactly match the number of columns in the matrix.
Naive matrix multiplication algorithm in MQL5:
Matrix multiplication example
An example of multiplying a horizontal vector by a matrix
An example of how to multiply a matrix by a vertical vector
An example of scalar (dot) product of vectors