mmul, mmdiv - Multiplication and Division

Prev Next

Function Names

mmul, mdiv

Description

These functions do true matrix multiplication and division (and not not simple scalar multiplication or division) Matrices must be provided as 2-level parameter 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.

Call as: function

Restrictions

Indirect parameter passing is disabled

Parameter count

2

Parameters

No.TypeDescription
1
input
matrix of numerals Left Matrix

2
input
matrix of numerals Right Matrix

Return value

TypeDescription
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

Exceptions

Mismatching matrix sizes
Division: Matrices are not squares

Examples

      echo( mmul ( {{1,2},{3,4}}, {{8,6},{4,2}} ) ); // returns {{16,10},{40,26}}
      echo( mdiv ( {{1,2},{3,4}}, {{3,1},{1,2}} ) ); // returns {{0,1}, {0.4,1.8}}

Output

{{16,10},{40,26}}
{{0,1},{0.4,1.8}}
Try it yourself: Open LIB_Function_mmul.b4p in B4P_Examples.zip. Decompress before use.