Mathematical Functions

From SysCAD Documentation

Jump to: navigation, search

Navigation: PGMs

The PGM Language supports the following math functions. All Function names are case insensitive.

Mathematical Functions See Also: Math Function Examples
Function Syntax Description
Sin variable = Sin(variable1) The Sin function, returns the sine of the argument in radians. Variable1 = an angle in radians
Cos variable = Cos(variable1) The Cos function, returns the cosine of the argument in radians. Variable1 = an angle in radians
Tan variable = Tan(variable1) The Tan function, returns the tangent of the argument in radians. Variable1 = an angle in radians
ATan2 variable = ATan2(y1, y2, x1, x2) The ATan2 function, returns the angle, in radians, given by the two points.
Abs variable = Abs(variable1) The Abs function, returns the absolute value of variable1
Sqrt variable = Sqrt(variable1) The Sqrt function, returns the square root of variable1.
Note: If variable1 is negative an error occurs as the operation is undefined.
Exp variable = Exp(variable1) The Exp function, returns the exponential of variable1.
Ln variable = Ln(variable1) The Ln function, returns the natural logarithm of variable1.
Note: If variable1 is negative an error occurs as the operation is undefined.
Log variable = Log(variable1) The Log function, returns the logarithm of variable1.
Note: If variable1 is negative an error occurs as the operation is undefined.
Pow variable = Pow(variable1, variable2) OR
variable = variable1^variable2
The Pow function, raises variable1 to the power of variable2. Alternatively, the ^ operator can be used.
Note: If variable1 is negative and variable2 is not an integer an error occurs as the operation is undefined.
In the SysCAD configuration file - Calculations, where Exp function is not available, use 2.718281828^(Variable) to represent the Exp function.
Related Topic: Calculation_Configuration
Max variable = Max(variable1, variable2) The Max function, returns the maximum of variable1 and variable2.
Min variable = Min(variable1, variable2) The Min function, returns the minimum of variable1 and variable2.
Range variable = Range(low_limit, variable1, hi_limit) The Range function, ranges variable1 between the two limits.
Trunc variable = Trunc(variable1) The Trunc function, returns the integer part of variable1.
Round variable = Round(variable1) The Round function, rounds variable1 to the closest integer variable.
Roundup variable = RoundUp(variable1, decimals) Variable1: is any real number that you want rounded up; decimals - is the number of digits to which you want to round number.
If decimals is 0, then number is rounded up to the nearest integer.
If decimals is less than 0, then number is rounded up to the left of the decimal point.
Mod variable = Mod(numerator, denominator) The Mod function, returns the remainder of numerator divided by denominator. The result and the variables may be double variable types. See also Div.
Note: Division by zero will result in an error as it is undefined.
Div variable = Div(numerator, denominator)The Div function, returns the quotient of numerator divided by denominator. The result is a long data type and the parameters may be double variable types. See also Mod.
Note: Division by zero will result in an error as it is undefined.
IsNAN variable = IsNAN(variable1) variable1 = double to be tested; The IsNAN function, returns true if variable1 is NAN (not a number) otherwise it returns false. Variable1 should be a double.
See also NAN in Predefined Constants and Variables.


Math Function Examples

DOUBLE   f@
LONG     w@
BIT      i*
BYTE     z*
CONST DOUBLE g = 2.5
CONST DOUBLE h = -3.4

f = sin(g) 	         ;f=0.598 	
f = cos(g) 	         ;f=-0.801	
f = tan(h) 	         ;f=-0.264	
f = atan2(1,2,1,2) 	 ;f=0.785	
f = abs(g) 	         ;f=2.5	
f = abs(h) 	         ;f=3.4	
f = sqrt(g) 	         ;f=1.581	
f = sqrt(h) 		 ;f=* (NAN)	(error)
f = exp(g) 	         ;f=12.182	
f = exp(h) 	         ;f=0.0334	
f = ln(g) 	         ;f=0.916	
f = ln(h) 	         ;f=* (NAN) 	(error)
f = ln(0) 	         ;f=-1.#INF 	(error)
f = log(g) 	         ;f=0.398	
w = log(h) 	         ;f=-2147483648 (error)
f = pow(g,h) 	         ;f=0.044	
f = pow(h,g) 	         ;f=* (NAN)	(error)
f = trunc(g) 	         ;f=2.0	
f = trunc(h) 	         ;f=-3.0	
f = round(g) 	         ;f=3.0	
f = round(h) 	         ;f=-3.0	
w = mod(7,3) 	         ;w=1	
w = div(7,3) 	         ;w=2	
f = mod(3.4,1.1) 	 ;f=0.1	
f = div(3.4,1.1) 	 ;f=3.0	
f = mod(g,h) 	         ;f=2.5	
f = mod(h,g) 	         ;f=-0.9	
f = mod(h,0) 	         ;f=* (NAN) 	(error)
w = div(g,h)	         ;w=0	
w = div(h,g)	         ;w=1	
f = min(g,h) 	         ;f=-3.4	
f = max(g,h) 	         ;f=2.5	
f = range(0,h,4) 	 ;f=0.0	
f = range(0,g,4) 	 ;f=2.5	
f = range(h,-4.2,g) 	 ;f=-3.4	
f = range(g,-4.2,h) 	 ;f=2.5	
f = Round(2.5)               ;rounds to 3
f = Round(0.1)               ;rounds to 0
f = Round(-3.7)              ;rounds to -4
f = Round(-3.4)              ;rounds to -3
f = ROUNDUP(3.2,0)           ;Rounds 3.2 up to zero decimal places (4)
f = ROUNDUP(76.9,0)          ;Rounds 76.9 up to zero decimal places (77)
f = ROUNDUP(3.14159, 3)      ;Rounds 3.14159 up to three decimal places (3.142) 
f = ROUNDUP(-3.14159, 1)     ;Rounds -3.14159 up to one decimal place (-3.2) 
f = ROUNDUP(31415.92654, -2) ;Rounds 31415.92654 up to 2 decimal places to the left of the decimal (31500)
f = ROUNDUP(3.2,-3)          ;Rounds 3.2 up to 3 decimal places to the left of the decimal (1000)
 
Example: Calculating pH

Double Tank1_pH@, H_Concentration@("ConcMl", "mol/L")
H_Concentration = GetTag("P_001.Qo.CMlC:L.HCl (mol/L)")*1
Tank1_pH = -1*Log(H_Concentration)

$
Personal tools
Document Sections