Mathematical functions

As well as providing intrinsic arithmetic operations for different data types (See Storage - Variable Types) Open GENIE provides several basic functions for performing mathematical operations. These are coded generically so that the same function can be applied to any data type which is capable of undergoing the operation. For example, the Sin() function may be called for a single number, an array or a data workspace. Normally, the result of the operation is of the same data type as the value operated upon. Where the operand contains several values (eg an array), each value is operated on individually in isolation to the others and an individual result is calculated for that value.

For example we can create an array of real numbers, and square root them all in one go.

>> my_numbers = Dimensions(10,20) # First create a 10 x 20 array
>> fill my_numbers 1.0 1.0	  # Fill the array with some data
>> printn my_numbers
[1.0 2.0 3.0 4.0 5.0 ...] Array(10 20 )
>> printn sqrt(my_numbers)	  # print the square roots.
[1.0 1.414213 1.732050 2.0 2.236067 ...] Array(10 20 )

When one of these generic operations is applied to a data workspace, a separate routine is called which allows the user to define the operations that are carried out (see Workspace Operations).

Trigonometric Functions

Arccos()
Arcsin()
Arctan()
Cos()
Sin()
Tan()

Transcendental Functions

Exp()
Ln()
Log()

Miscellaneous Functions

Abs()
Sqrt()

COMMAND REFERENCE

All commands are listed here under the appropriate section. This is the definitive description for all the Open GENIE maths functions.

Trigonometric Functions

Arccos()

Generic trig functions.

ARCCOS(x) x=Generic Arccosine in radians.

example:

	# print result in degrees
	y = Arccos(0.5) * 180 / $pi
	#take the arccos of all elements in an array
	a = Dimensions(10)	# create a 10 element array
	fill a 0.5		# Set all elements to 0.5
	y = Arccos(a)

Note: These functions can be applied to all numeric types (including arrays & workspaces).

Arccos()

These function returns an Arccosine value in radians.

Parameters:

X (Generic)

A single number, array or workspace containing the values to which the appropriate trig function is to be applied. Angles must be specified in radians. Undefined values passed to this function will be returned as an undefined result.

RESULT = (Generic)

Angle(s) in radians.

Arcsin()

Generic trig functions.

ARCSIN(x) x=Generic Arcsine in radians.

example:

	# print result in degrees
	y = Arcsin(0.5) * 180 / $pi
	#take the arcsine of all elements in an array
	a = Dimensions(10)	# create a 10 element array
	fill a 0.5		# Set all elements to 0.5
	y = Arcsin(a)

Note: These functions can be applied to all numeric types (including arrays & workspaces).

Arcsin()

These function returns an Arcsine value in radians.

Parameters:

X (Generic)

A single number, array or workspace containing the values to which the appropriate trig function is to be applied. Angles must be specified in radians. Undefined values passed to this function will be returned as an undefined result.

RESULT = (Generic)

Angle(s) in radians.

Arctan()

Generic trig functions.

ARCTAN(x) x=Generic Arctangent in radians.

example:

	# print result in degrees
	y = Arctan(1000.0) * 180 / $pi
	#take the arctan of all elements in an array
	a = Dimensions(10)	# create a 10 element array
	fill a 0.5		# Set all elements to 0.5
	y = Arctan(a)

Note: These functions can be applied to all numeric types (including arrays & workspaces).

Arctan()

These function returns an Arctangent value in radians.

Parameters:

X (Generic)

A single number, array or workspace containing the values to which the appropriate trig function is to be applied. Angles must be specified in radians. Undefined values passed to this function will be returned as an undefined result.

RESULT = (Generic)

Angle(s) in radians.

Cos()

Generic trig function.

COS(x) x=Generic Cosine in radians.

example:

	# take cosine of angle in degrees
	y = Cos(90.0 * 180.0/$PI)
	#take the cosine of all elements in an array
	a = Dimensions(10)	# create a 10 element array
	fill a $pi*2.0		# Set all elements to pi*2
	y = Cos(a)

Note: This function can be applied to all numeric types (including arrays & workspaces).

Cos()

These function calculates the cosine of an angle in radians.

Parameters:

X (Generic)

A single number, array or workspace containing the values to which the trig function is to be applied. Angles must be specified in radians. Undefined values passed to this function will be returned as an undefined result.

RESULT = (Generic)

Cosine of the angle(s) given in radians.

Sin()

Generic trig function.

SIN(x) x=Generic Sin in radians.

example:

	# take sin of angle in degrees
	y = sin(40.0 * 180.0/$PI)
	#take the sin of all elements in an array
	a = Dimensions(10)	# create a 10 element array
	fill a 0.5		# Set all elements to 0.5
	y = Sin(a)

Note: This function can be applied to all numeric types (including arrays & workspaces).

Sin()

These function calculates the sine of an angle in radians.

Parameters:

X (Generic)

A single number, array or workspace containing the values to which the trig function is to be applied. Angles must be specified in radians. Undefined values passed to this function will be returned as an undefined result.

RESULT = (Generic)

Sine of the angle(s) given in radians.

Tan()

Generic trig function.

TAN(x) x=Generic Tangent in radians.

example:

	# take tangent of angle in degrees
	y = Tan(90.0 * 180.0/$PI)
	#take the tangent of all elements in an array
	a = Dimensions(10)	# create a 10 element array
	fill a 0.5		# Set all elements to 0.5
	y = Tan(a)

Note: This function can be applied to all numeric types (including arrays & workspaces).

Tan()

These function calculates the tangent of an angle given in radians.

Parameters:

X (Generic)

A single number, array or workspace containing the values to which the trig function is to be applied. Angles must be specified in radians. Undefined values passed to this function will be returned as an undefined result.

RESULT = (Generic)

Tangent of the angle(s) given in radians (or undefined where the function result is beyond the precision of the machine).

Transcendental Functions

Exp()

Generic transcendental functions.

EXP(x) x=Generic Exponentiate

example:

	# antilog a data array
	# which is in logs to base 10
	data = Exp( w.y * ln(10.0) )

Note: These functions can be applied to all numeric types (including arrays & workspaces).

Exp()

Exponentiates, ie takes ex

Parameters:

X (Generic)

A single number, array or workspace containing the values to be exponentiated. Undefined values passed to this function will be returned undefined.

RESULT = (Generic)

Exponentiated value(s).

Ln()

Generic transcendental functions.

LN(x) x=Generic Log to the base e

example:

	# Take logs to base e of a data array
	lndata = Ln(w.y)

Note: These functions can be applied to all numeric types (including arrays & workspaces).

Ln()

Take natural logarithms.

Parameters:

X (Generic)

A single number, array or workspace containing the values to take logs of. Undefined values passed to this function will be returned undefined. Illegal values (ie negative numbers are permitted) but will return an undefined result.

RESULT = (Generic)

Either the log of the value or an undefined result.

Log()

Generic transcendental functions.

LOG(x) x=Generic Log to the base 10

example:

	# Take logs of a data array
	log10data = Log(w.y)

Note: These functions can be applied to all numeric types (including arrays & workspaces).

Log()

Take logs to base10.

Parameters:

X (Generic)

A single number, array or workspace containing the values to take logs of. Undefined values passed to this function will be returned undefined. Illegal values (ie negative numbers are permitted) but will return an undefined result.

RESULT = (Generic)

Either the log of the value or an undefined result.

Miscellaneous Functions

Abs()

Calculate the absolute values.

ABS(x) x=Generic Calculate |x|.

example:

	# Print the absolute value
	printn abs(-3.3)
	3.3

Note: This function can be applied to all numeric types (including arrays & workspaces).

Abs()

Calculates the absolute value of a number or of the numbers in an array. All negative numbers will be returned as positive numbers of the same magnitude.

Parameters:

X (Generic)

A single number, array or workspace containing the values for which to find |x|. Undefined values passed to this function will be returned undefined. Illegal values (ie negative numbers are permitted) but will return an undefined result.

RESULT = (Generic)

Either the absolute value or an undefined result.

Sqrt()

Calculate the square root of a value.

SQRT(x) x=Generic Calculate the square root.

example:

	# Calculate the square root of Pi
	printn Sqrt($PI)
	1.77245310234149

Note: This function can be applied to all numeric types (including arrays & workspaces).

Sqrt()

Calculates the square root of a number.

Parameters:

X (Generic)

A single number, array or workspace containing the values to square root. Undefined values passed to this function will be returned undefined. Illegal values (ie negative numbers are permitted) but will return an undefined result.

RESULT = (Generic)

Either the square root of the value or an undefined result.