Fisheries and Oceans Canada / Pêches et Océans Canada - Government of Canada / Gouvernement du Canada Fisheries and Oceans Canada / Pêches et Océans Canada - Government of Canada / Gouvernement du Canada
 
Français Contact Us Help Search Canada Site
Home What's New DFO National Site Map Media

Fisheries & Oceans
 
 
Maritimes Region
Fishing Industry
General Public
Marine & Oceans Industry
Media
Students and Teachers
Scientists and Researchers
 
AconIcon ACON       Home/Topics   |   Commands

Math Functions


The basic numeric data types are:

integer scalar 4
real scalar 4.5
integer vector 4 5 6
real vector 4.5 5.6 8.2
integer matrix 4 5 6
7 8 9
real matrix 4.5 5.6 8.2
8.4 9.2 10

For more information on data types see Object_Type. Unless noted otherwise, all of the math functions accept a scalar value, a vector or a matrix as arguments, and return results of the same rank. Illegal operations return a NAN (not a number) value, or issue an error message.

None of the math functions have an initial state.

The math functions include:
Acos, Asin, Atan, Atan2, Cat, Ceil, Cos, Exp, Fabs, Floor, Int, Log, Log10, Max, Min, Mod, Nan, Pow, Rand, Rand_Seed, Sin, Sqrt, Tan, Tolerance, RMax, RMin,and Execute.


Acos

This function requires a single numeric argument, for which the arc cosine is calculated and returned as the result.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

acos(value);

x = acos(0.5);
x
1.0472


Asin

This function requires a single numeric argument, for which the arc sine is calculated and returned as the result.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

asin(value);
x = asin(0.5);
x
0.523599


Atan2

This function requires 2 numeric scalar arguments, for which the arc tangent of the ratio of the 1st number over the 2nd number is calculated and returned as the result.

There are 2 parameters:
value1 - any valid integer or floating point number, vector or matrix.
value2 - any valid integer or floating point number, vector or matrix.

atan2(value1,value2);

x = atan2(10,20);
0.463648


Atan

This function requires a numeric argument, for which the arc tangent is calculated and returned as the result.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

atan(value);

x = atan(0.5);


Cat

This function catenates 2 or more numeric values and returns a single numeric result. Cat also works with strings, see Strings Cat.

There are 3 or more parameters:
dim - the index of the dimension over which the catenation takes place (0 = catenate into a vector, 1 = catenate into a matrix adding elements as new rows, 2 = catenate into a matrix adding elements as new columns).
value - any valid integer or floating point number, vector, or matrix.
valuen - any valid integer or floating point number, vector, or matrix.

cat(dim,value,value,[value]);

x = 1 2 3
y = 4 5 6
cat(0,x,y)
1 2 3 4 5 6

cat(1,x,y)
1 2 3
4 5 6

cat(2,x,y,x)
1 4 1
2 5 2
3 6 3


Ceil

This function requires a single numeric argument which is rounded up to the next larger integer and returned as the result.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

ceil(value);

x = ceil(10.6);
x
11


Cos

This function requires a single numeric argument, for which the cosine is calculated and returned as the result.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

cos(value);

x = cos(0.5);


Exp

This function requires a single numeric argument. The result is e raised to the power of the argument.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

exp(x);

newvalue = exp(2);

See the example VonB Curves.


Fabs

This function requires a numeric argument, which is converted to a positive number and returned as the result as a floating point number.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

fabs(value);

plus = fabs(-123);


Floor

This function requires a single numeric argument which rounded down the next lower integer and returned as the result. The data type remains unchanged, unlike the Int function which always returns an integer.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

floor(value);

x = floor(10.6); ...x will be 10


Int

This function requires a numeric argument, which is truncated to an integer and returns this integer as the result.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

integer = int(value);

decade = int(1995.0 / 10.0) * 10;
print(decade);
1990


Log10

This function requires a single numeric argument for which the log to the base 10 is calculated and returned as the result.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

log10(value);

new = log10(100);


Log

This function requires a single numeric argument for which the log to the base e is calculated and returned as the result.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

log(value);

new = log(100);


Max

This function requires one or more numeric arguments for which the maximum is calculated and returned as the result. If all arguments are integers, the result is an integer, otherwise a floating point number is returned.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

max(value,[value]...);

new = 100.5
new = max(new,100);
print(new)
100.5


Min

This function requires one or more numeric arguments for which the minimum is calculated and returned as the result. If all arguments are integers, the result is an integer, otherwise a floating point number is returned.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

min(value,[value]...);

new = 100.5
new = min(new,100);
print(new)
100


Mod

This function requires 2 numeric arguments for which the modulus (the remainder) is calculated for the 1st number divided by the 2nd number and returned as the result.

There are 2 parameters:
value - any valid integer or floating point number, vector, or matrix.
divisor -the integer or floating point scalar to divide by.

mod(value,divisor);

mod(1 2 3 4 5 6,3);
1 2 0 1 2 0


Nan

This function returns the value 1.0E-4915 (or the current value of DBL_MIN as defined by the implementation of the ANSI standard if not this number). Number conversion (e.g. num() will return a number equal to this value when unable to convert the number.

There are no parameters

nan();

if (x == nan()) then y = 100;


Pow

This function requires 2 numeric arguments. The 1st number is raised to the power of the 2nd number and returned as the result.

There are 2 parameters:
value1 - any valid integer or floating point number, vectors or matrices are allowed.
value2 - any valid integer or floating point number, vectors or matrices not allowed.

power(value, value);

squared = pow(10,2);
pow(1 2 3,2)
1 4 9


Rand

This function returns a random number between 0.0 and 1.0, (or the optional limit value). If the limit value is an integer, then the random number is an integer.

There is 1 optional parameter:
limit - any valid integer or floating point scalar, vector, or matrix which will be the upper limit of the result.

rand();

rand(limit);

rand();
0.368053

rand(2.5);
2.45865

rand(3 3 3 3 3);
3 2 1 0 1

Note: Integer random numbers are generated using the system supplied rand() routine which is machine dependant.
The floating point routine was based on the same rand() routine, and is now (version 8.07) based on the ran1() routine from the book "Numerical Receipes in C" 1988. Press, W.H., Flannery, B., Teukolsky, S., and W. Vetterling. Cambridge University Press. page 210. This new version is based on 3 linear congruential generators whose period (for practical purposes) is infinite.


Rand Seed

This function sets the random number generator seed value. There is no result.

There is 1 parameter:
starting seed - an optional integer. If no value is specified, the current clock time is used as the seed.

rand_seed(seed);
rand_seed();

rand_seed(22000);


Sin

This function requires a single numeric argument, for which the sine is calculated and returned as the result.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

sin(value);

x = sin(0.5);

See the example User-defined Functions.


Sqrt

This function requires a single numeric argument. The result is the square root of the argument.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

sqrt(value);

x = sqrt(4);


Tan

This function requires a single numeric argument, for which the tangent is calculated and returned as the result.

There is 1 parameter:
value - any valid integer or floating point number, vector, or matrix.

tan(value);

x = tan(0.5);


Tolerance

This function requires a single numeric argument, the value of the tolerance limit to use for floating point equality testing. The function returns no result. The default is 4 * DBL_EPSILON (the smallest representable floating point number).

There is 1 parameter:
value - any small floating point number.

tolerance(value);

tolerance(0.0000000001);


RMax

This function requires a single numeric argument, the number for which the user wants to obtain its rounded maximum. The function returns the rounded maximum of the number from a pre-defined set of numbers.

There is 1 parameter:
number - any number or sequence of numbers the user wants to get its round maximum.

rmax(number);

rmax(123);
150

rmax(345.543);
400

distinct(rmax(seq(1,1000000)));
1 2 3 4 5 7.5 10 15 20 25 30 40 50 75 100 150 200 250 300 400 500 750 1000 1500 2000 2500 3000 4000 5000 7500 10000 15000 20000 25000 30000 40000 50000 75000 100000 150000 200000 250000 300000 400000 500000 750000 1E+006

distinct(rmax(seq(.001,1,.001))); 0.001 0.01 0.015 0.1 0.15 1 1.5


RMin

This function requires a single numeric argument, the number for which the user wants to obtain its rounded minimum. The function returns the rounded minimum of the number from a pre-defined set of numbers.

There is 1 parameter:
number - any number or sequence of numbers the user wants to get its round minimum.

rmin(number);

rmin(578.987);
500

distinct(rmin(seq(1,1000000)));
1 2 3 4 5 7.5 10 15 20 25 30 40 50 75 100 150 200 250 300 400 500 750 1000 1500 2000 2500 3000 4000 5000 7500 10000 15000 20000 25000 30000 40000 50000 75000 100000 150000 200000 250000 300000 400000 500000 750000 1E+006

distinct(rmin(seq(.001,1,.001)));
0.001 0.002 0.003 0.004 0.005 0.0075 0.01 0.015 0.02 0.025 0.03 0.04 0.05 0.075 0.1 0.15 0.2 0.25 0.3 0.4 0.5 0.75 1


Execute

This function requires a character string as the argument which is executed as extalk code. If an error occurs while executing the string, the currently executing operation will be interupted. This function may return a result.

There is 1 parameter:
string - a character string to be executed.

execute(string);

execute("a = 5.0");
print(a);
5.000000
execute("6 + 5")*2
22


AconIcon ACON       Home/Topics   |   Commands



Last Modified : 2003-11-19