A Scripting Language for Web, Linux and Windows

A Scripting Language for Web, Linux and Windows

Module: math

This module is only available in Windows versions of V1. Support higher mathematical functions. The module must be loaded with dl('math');

Working with matrixes

Function/Arguments Return Description
mx (mixed matrix1, string operation, [, mixed matrix2 ]) array Do a matrix or vector operation with matrix1 and matrix2. A matrix is defined as an array with rows and columns. Example of a 2x3 matrix with 2 rows and 3 columns: [[1,2,3],[3,4,5]]. Example of a 3-dimensional vector: [1,2,3]. Matrixes can be also scalar numbers. For special operations matrix2 is not required. The following operations are possible: Arithmetic: '+', '-', '*', '/' Cross product: 'x' Dot product: '.' For special operations see table below. On success the result matrix is returned as array or false if error occured.

Special mx() operations:


<?v1
dl 
("math");

mx ([[1,2,3], [3,4,5]], "transpose"); // Result: [[1,3],[2,4],[3,5]]
mx ([[1,2], [3,4]], "adjoint"); // Result: [[1,3],[2,4]]
mx ([[1,2,3],[4,5,6]], "sum"); // Result: 21
mx ([[1,2,3],[4,5,6]], "prod"); // Result: 720
mx ([[1,2,3],[4,5,6]], "mean"); // Result: 3.5
mx ([[1,2,3],[4,5,6]], "minCoeff"); // Result: 1
mx ([[1,2,3],[4,5,6]], "maxCoeff"); // Result: 6
mx ([[1,2,3],[4,5,6],[6,7,8]], "trace");  // Result: 14 (The trace of a matrix is the sum of the diagonal coefficients 1+5+8.)
mx ([[1,2],[3,4]], "squaredNorm"); // Result: 30 (Euclidean squared norm. Its the sum of squared absolute values of its coefficients and equal to the dot product of the vector by itself.)
mx ([[1,2],[3,4]], "norm"); // Result: 5.4772255750517 ("norm" operation is the square root of "squaredNorm")
mx ([[1,2],[3,4]], "all"); // Result: true (all coefficients != 0)
mx ([[0,0],[0,0]], "any"); // Result: false (any coefficient != 0)
mx ([[1,2],[3,0]], "count"); // Result: 3 (number of coefficients!=0)

?>

Working with big integer numbers

Function/Arguments Return Description
bigint (mixed number1, string operation, mixed number2) mixed Do a operation with big integer number1 and number2. The following operations are possible: Arithmetic: '+', '-', '*', '/' Power '**' On success the result is returned as long string or number. On error false is returned.
biguint (mixed number1, string operation, mixed number2) mixed Do a operation with big unsigned integer number1 and number2. The following operations are possible: Arithmetic: '+', '-', '*', '/' Power '**' On success the result is returned as long string or number. On error false is returned.

<?v1
dl 
("math");

// -80538738812075974^3 + 80435758145817515^3 + 12602123297335631^3 = 42
bigint ("-80538738812075974""**"3);
bigint ("80435758145817515""**"3);
bigint ("12602123297335631""**"3);
print (
bigint (bigint (a"+"b), "+"c)); // Result 42

?>

back to Home