Matrix Functions

Prev Next

Introduction

B4P provides a library of powerful matrix functions. While vectors are modeled as 1-dimensional parameter sets containing numerals, matrices are modeled as parameter sets (rows) containing parameter sets containing numerals (columns). Example: {{ 1, 2, 3 }, { 4, 5, 6 }} is a matrix consisting of 2 rows and 3 columns:

| 1 2 3 |
| 4 5 6 |

  • mmul: Matrix multiplication
  • minv: Matrix inversion
  • mdiv: Matrix division
  • mdet: Calculates determinant
  • linear: Solves a set of linear equations (Gaussian elimination)

You may possibly be missing the functions like madd and msub for addition and subtraction. These two operations can be implmented with direct matrix mathematics using deep operators as shown below:

  • Matrix addition: a[] +^^ b[]
  • Matrix subtraction: a[] -^^ b[]
  • Scalar multiplication: a[] *^^ b[]
  • Scalar division: a[] /^^ b[]


Following functions, also described in this section, allow any types in their matrices because contents are only moved and not calculated:

  • horizontal: Converts a flat or vertical matrix to a horizontal matrix (1 row, several column elements)
  • vertical: Converts a flat or horizontal matrix to a vertical matrix (1 column, several row elements)
  • flat: Flattens the matrix to all values arranged in a simple parameter set
  • diagonal: Creates a matrix with values along the diagonal and zero in the remaining fields
  • transpose: Transposes a matrix




Procedures and Functions Provided:


matrix multiplication, matrix division:
    mdiv
    mmul

matrix inversion:
    minv

matrix determinant:
    mdet

linear equation:
    linear

Make matrix horizontal:
    horizontal

Make matrix vertical:
    vertical

Flatten matrix:
    flat

Put values diagonally into matrix:
    diagonal

transpose matrix:
    transpose