MATH functions
The math function performs many simple mathematical calculations that can be programmed in Basic but there are speed advantages to coding looping structures in C and there is the advantage that once debugged they are there for everyone without re-inventing the wheel.
For array operations, arrays are typically specified as DIM array(n_columns, n_rows) and dimensions respect OPTION BASE.
Trigonometric & Logarithmic Functions
MATH(ATAN3 x,y)
Returns ATAN3 of x and y
MATH(COSH a)
Returns the hyperbolic cosine of a
MATH(LOG10 a)
Returns the base 10 logarithm of a
MATH(SINH a)
Returns the hyperbolic sine of a
MATH(TANH a)
Returns the hyperbolic tan of a
Random & Encoding Functions
MATH(RAND)
Returns a random number 0.0 <= n < 1.0 using the "Mersenne Twister algorithm. If not seeded with MATH RANDOMIZE the first usage seeds with the time in microseconds since boot
MATH(BASE64 ENCODE/DECODE in$/in(), out$/out())
Returns the length of out$/out(). This base64 encodes or decodes the data in in
and puts the result in out.
Where arrays are used as the output they must be big enough relative to the input and the direction. Encryption increases length by 4/3 and decryption decreases it by 3/4.
MATH(CRCn data [,length] [,polynome] [,startmask] [,endmask] [,reverseIn] [,reverseOut]
Calculates the CRC to n bits (8, 12, 16, 32) of "data". "data" can be an integer or floating point array or a string variable. "Length" is optional and if not specified the size of the array or string length is used. The defaults for
startmask, endmask reverseIn, and reversOut are all zero. reverseIn, and reversOut are both Booleans and take the value 1 or 0. The defaults for polynomes are CRC8=&H07, CRC12=&H80D, CRC16=&H1021, crc32=&H04C11DB7 eg, for crc16_CCITT use MATH(CRC16 array(), n,, &HFFFF)
Basic Statistical Functions
MATH(MEAN a())
Returns the average of all values in the a() array, a() can have any number of dimensions
MATH(MEDIAN a())
Returns the median of all values in the a() array, a() can have any number of dimensions
MATH(SUM a())
Returns the sum of all values in the a() array, a() can have any number of dimensions
MATH(SD a())
Returns the sample standard deviation of all values in the a() array, a() can have any number of dimensions
MATH(MIN a(), [index%])
Returns the minimum of all values in the a() array, a() can have any number of dimensions. If the integer variable is specified then it will be updated with the index of the minimum value in the array. This is only available on one- dimensional arrays.
MATH(MAX a() [,index%])
Returns the maximum of all values in the a() array, a() can have any number of dimensions. If the integer variable is specified then it will be updated with the index of the maximum value in the array. This is only available on one- dimensional arrays
Advanced Statistical Functions
MATH(CHI a())
Returns the Pearson's chi-squared value of the two dimensional array a())
MATH(CHI_p a())
Returns the associated probability in % of the Pearson's chi-squared value of the two dimensional array a())
MATH(CORREL a(), a())
Returns the Pearson's correlation coefficient between arrays a() and b()
MATH(CROSSING array() [,level] [,direction]
This returns the array index at which the values in the array pass the "level" in the direction specified. level defaults to 0. Direction defaults to 1 ( valid values are -1 or 1)
Vector & Matrix Operations
MATH(MAGNITUDE v())
Returns the magnitude of the vector v(). The vector can have any number of elements
MATH(DOTPRODUCT v1(), v2())
Returns the dot product of two vectors v1() and v2(). The vectors can have any number of elements but must have the same cardinality
MATH(M_DETERMINANT array!())
Returns the determinant of the array. The array must be square.
Control Systems
MATH(PID channel, setpoint!, measurement))
This function must be called in the PID callback subroutine for the channel
specified and returns the output of the controller function.
The setpoint value is the desired state that the controller is trying to achieve.
The measurement is the current value of the real world.
https://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=17263 For an example of setting up and running a PID controller
Array Management
See BOUND for array boundary information.