Matrix¶
Reference¶
- class Matrix¶
- module:
-
- new(rows, columns, value)¶
Create new matrix
if rows is a table then sets rows as matrix. if rows is a table of structure {1,2,3} then it sets it as a vector matrix. if rows and columns are given and are numbers, returns a matrix with size rowsxcolumns. if num is given then returns a matrix with given size and all values set to num. if rows is given as number and columns is “I”, will return an identity matrix of size rowsxrows.
- static add(m1, m2)¶
Add two matrices. m2 may be of bigger size than m1
- static sub(m1, m2)¶
Subtract two matrices. m2 may be of bigger size than m1
- static mul(m1, m2)¶
Multiply two matrices. m1 columns must be equal to m2 rows
e.g. #m1[1] == #m2
- static div(m1, m2)¶
Divide two matrices. m1 columns must be equal to m2 rows.
m2 must be square, to be inverted, if that fails returns the rank of m2 as second argument. e.g. #m1[1] == #m2; #m2 == #m2[1]
- static mulnum(m1, num)¶
Multiply matrix with a number.
num may be of type ‘number’ or ‘complex number’. strings get converted to complex number, if that fails then to symbol
- static divnum(m1, num)¶
Divide matrix by a number.
num may be of type ‘number’ or ‘complex number’. strings get converted to complex number, if that fails then to symbol.
- static det(m1)¶
Calculate the determinant of a matrix.
m1 needs to be square. Can calc the det for symbolic matrices up to 3x3 too. The function to calculate matrices bigger 3x3 is quite fast and for matrices of medium size ~(100x100) and average values quite accurate. here we try to get the nearest element to | 1 |, (smallest pivot element) os that usually we have | mtx[i][j]/subdet | > 1 or mtx[i][j]. with complex matrices we use the complex.abs function to check if it is bigger or smaller
- static invert(m1)¶
Get the inverted matrix or m1
matrix must be square and not singular on success: returns inverted matrix on failure: returns nil,’rank of matrix’