LuaSTG-x Core API
|
Public Member Functions | |
static function | __add (local a, local b) |
static function | __concat (local a, local b) |
static function | __div (local a, local b) |
static function | __eq (local a, local b) |
static function | __mul (local a, local b) |
static function | __pow (local a, local b) |
static function | __sub (local a, local b) |
static function | __tostring (local a) |
static function | abs (local a) |
applies abs function to symbol More... | |
static function | add (local m1, local m2) |
functions are designed to be light on checks More... | |
static function | columns (local mtx) |
static function | concath (local m1, local m2) |
static function | concatv (local m1, local m2) |
static function | copy (local m1) |
local functions to copy matrix values More... | |
static function | cross (local m1, local m2) |
function | det () |
static function | div (local m1, local m2) |
static function | divnum (local m1, local num) |
function | dogauss () |
locals More... | |
static function | elementstostrings (local mtx) |
static function | getelement (local mtx, local i, local j) |
function | gsub (local from, local to) |
Performs string.gsub on symbol. More... | |
function | invert () |
static function | ipairs (local mtx) |
static function | latex (local mtx, local align) |
static function | len (local m1) |
static function | makereplacer (local ...) |
creates function that replaces one letter by something else More... | |
static function | mul (local m1, local m2) |
static function | mulnum (local m1, local num) |
static function | new (local o) |
note '...' is always faster than 'arg1,arg2,...' if it can be used More... | |
function | new (local rows, local columns, local value) |
access to the metatable we set at the end of the file More... | |
static function | normf (local mtx) |
static function | normmax (local mtx) |
static function | pow (local m1, local num) |
static function | print (local ...) |
static function | random (local mtx, local start, local stop, local idp) |
static function | replace (local m1, local func, local ...) |
static function | root (local m1, local root, local iters) |
static function | rotl (local m1) |
static function | rotr (local m1) |
static function | round (local mtx, local idp) |
Functions changing the matrix itself. More... | |
static function | rows (local mtx) |
static function | scalar (local m1, local m2) |
a vector is defined as a 3x1 matrix More... | |
static function | setelement (local mtx, local i, local j, local value) |
static function | size (local mtx) |
static function | solve (local m1) |
static function | sqrt (local a) |
applies sqrt function to symbol More... | |
static function | sqrt (local m1, local iters) |
you have to determin for yourself if the result is sufficent enough for you More... | |
static function | sub (local m1, local m2) |
static function | subm (local m1, local i1, local j1, local i2, local j2) |
static function | tostring (local mtx, local formatstr) |
symbol( arg ) More... | |
static function | transpose (local m1) |
function | type () |
Returns "symbol" if object is a symbol type, else nothing. More... | |
static function | type (local mtx) |
Public Attributes | |
string | _NAME |
string | _TYPE |
string | _VERSION |
table | symbol |
functions are designed to be light on checks
set __call behaviour of matrix
for matrix( ... ) as matrix.new( ... )so we get Lua errors instead on wrong input
matrix.<functions> should handle any table of structure t[i][j] = value
we always return a matrix with scripts metatable
cause its faster than setmetatable( mtx, getmetatable( input matrix ) )
note: real and complex matrices may be added, subtracted, etc.
Add two matrices; m2 may be of bigger size than m1
return number of columns
Concatenate two matrices, horizontal
will return m1 m2; rows have to be the same
e.g.: #m1 == #m2
Concatenate two matrices, vertical
will return m1
m2
columns have to be the same; e.g.: #m1[1] == #m2[1]
local functions to copy matrix values
Copy a matrix
simple copy, one can write other functions oneself
returns the Cross Product of two 3x1 matrices (vectors)
function det | ( | ) |
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
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]
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
function dogauss | ( | ) |
locals
Gauss elimination, Gauss-Jordan Method
this function changes the matrix itself
returns on success: true,
returns on failure: false,'rank of matrix'checking here for the element nearest but not equal to zero (smallest pivot element).
This way the factor
in dogauss
will be >= 1, which
can give better results. note: in –// ... //– we have a way that does no divison,
however with big number and matrices we get problems since we do no reducing
set the matrix elements to strings
IMPROVE: tostring v.s. tostringelements confusing
return specific element ( row,column )
returns element on success and nil on failure
Performs string.gsub on symbol.
for use in matrix.replace
function invert | ( | ) |
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'
iteration, same for complex
LaTeX output
returns the Length of a 3x1 matrix (vector)
creates function that replaces one letter by something else
makereplacer( "a",4,"b",7, ... )(x)
will replace a with 4 and b with 7 in symbol x.
for use in matrix.replace
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
note '...' is always faster than 'arg1,arg2,...' if it can be used
as we declaired on top of the page
local/shared metatable
matrix_meta Set add "+" behaviour Set subtract "-" behaviour Set multiply "*" behaviour Set division "/" behaviour Set unary minus "-" behavior Set power "^" behaviour
if opt is any integer number will do mtx^opt
(returning nil if answer doesn't exist)
if opt is 'T' then it will return the transpose matrix
only for complex:
if opt is '*' then it returns the complex conjugate matrix Set equal "==" behaviour Set tostring "tostring( mtx )" behaviour set __call "mtx( [formatstr] )" behaviour, mtx [, formatstr]
access to the symbolic metatable
access to the metatable we set at the end of the file
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
calculates the Frobenius norm of the matrix.
||mtx||_F = sqrt(SUM_{i,j} |a_{i,j}|^2)
calculates the max norm of the matrix.
||mtx||_{max} = max{|a_{i,j}|}
Does not work with symbolic matrices
Power of matrix; mtx^(num)
num is an integer and may be negative
m1 has to be square
if num is negative and inverting m1 fails
returns the rank of matrix m1 as second argument
print out the matrix, just calls tostring
fillmatrix with random values
for each element e in the matrix mtx, replace it with func(mtx, ...).
calculate any root of a matrix
source: http://www.dm.unipi.it/~cortona04/slides/bruno.pdf
m1 and root have to be given;(m1 = matrix, root = number)
conditions same as matrix.sqrt
returns same values as matrix.sqrt
Rotate Left, 90 degrees
Rotate Right, 90 degrees
return number of rows
a vector is defined as a 3x1 matrix
get a vector; vec = matrix{{ 1,2,3 }}^'T'
returns the Scalar Product of two 3x1 matrices (vectors)
set an element ( i, j, value )
returns 1 on success and nil on failure
get matrix size as string rows,columns
solve; tries to solve a symbolic matrix to a number
you have to determin for yourself if the result is sufficent enough for you
calculate the square root of a matrix using "Denman Beavers square root iteration"
condition: matrix rows == matrix columns; must have a invers matrix and a square root
if called without additional arguments, the function finds the first nearest square root to
input matrix, there are others but the error between them is very small
if called with agument iters, the function will return the matrix by number of iterations
the script returns:local average error square root function
Subtract two matrices; m2 may be of bigger size than m1
Submatrix out of a matrix
input: i1,j1,i2,j2
i1,j1 are the start element
i2,j2 are the end element
condition: i1,j1,i2,j2 are elements of the matrix
symbol( arg )
tostring function
same as symbol.to( arg )
set __call behaviour of symbol Converts object to string, optionally with formatting.
function type | ( | ) |
Returns "symbol" if object is a symbol type, else nothing.
get type of matrix, normal/complex/symbol or tensor
string _NAME |
string _TYPE |
string _VERSION |
table symbol |