MatMul
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]
matrix matrix::MatMul(
|
Multiplying a vector by a matrix: horizontal vector[K] * matrix[K][N] = horizontal vector[N]
vector vector::MatMul(
|
Multiplying a matrix by a vector: matrix[M][K] * vertical vector[K] = vertical vector[M]
vector matrix::MatMul(
|
Scalar vector multiplication: horizontal vector * vertical vector = dot value
scalar vector::MatMul(
|
Parameters
b
[in] Matrix or vector.
Return Value
Matrix, vector, or scalar, depending on the method used.
Note
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 MatrixProduct(const matrix& matrix_a, const matrix& matrix_b)
|
Matrix multiplication example
matrix a={{1, 0, 0},
|
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
void OnStart()
|
See also