mmul, mdiv
These functions do true matrix multiplication and division (and not not simple scalar multiplication or division)
Matrices must be provided as 2-level sets, e.g. {{1,2},{3,4}}
mmul: For matrix multiplications, the number of columns (and / rows) in the left matrix needs to match with the number of rows (/ columns) in the right matrix.
mdiv: For matrix divisions, both matrices need to be squares, i.e. row and column count must equal.
In case of division, 2nd matrix must also be a square matrix as it is inverted before a multiplication (like mmul) is applied. Result = A • B-1,
The function will reject calculations and assert exceptions if not all criteria are properly met.
Indirect parameter passing is disabled
2
No. | Type | Description |
---|---|---|
1 input |
matrix of numerals | Left Matrix |
2 input |
matrix of numerals | Right Matrix |
Type | Description |
---|---|
matrix of numerals | Result Matrix with number of rows as specified in the left matrix and number of columns as specified in the right matrix |
Mismatching matrix sizes
Division: Matrices are not squares
m1[] = {{1,2},{3,4}};
m2[] = {{8,6},{4,2}};
m3[] = {{3,1},{1,2}};
echo matrix( "0.0", 4, " | ", m1[], " * ", m2[], " = ", mmul( m1[], m2[] ) );
echo matrix( "0.0", 4, " | ", m1[], " / ", m3[], " = ", mdiv( m1[], m3[] ) );
| 1.0 2.0 | | 8.0 6.0 | | 16.0 10.0 |
| 3.0 4.0 | * | 4.0 2.0 | = | 40.0 26.0 |
| 1.0 2.0 | | 3.0 1.0 | | 0.0 1.0 |
| 3.0 4.0 | / | 1.0 2.0 | = | 0.4 1.8 |