Compute the absolute value of a number
y = abs(x)
The abs
function returns the absolute value of an arithmetic
type. If its argument is a complex number (Complex_Type
),
then it returns the modulus. If the argument is an array, a new
array will be created whose elements are obtained from the original
array by using the abs
function.
Compute the arc-cosine of a number
y = acos (x)
The acos
function computes the arc-cosine of a number and
returns the result. If its argument is an array, the
acos
function will be applied to each element and the result returned
as an array.
Compute the inverse cosh of a number
y = acosh (x)
The acosh
function computes the inverse hyperbolic cosine of a number and
returns the result. If its argument is an array, the
acosh
function will be applied to each element and the result returned
as an array.
Compute the arc-sine of a number
y = asin (x)
The asin
function computes the arc-sine of a number and
returns the result. If its argument is an array, the
asin
function will be applied to each element and the result returned
as an array.
Compute the inverse-sinh of a number
y = asinh (x)
The asinh
function computes the inverse hyperbolic sine of a number and
returns the result. If its argument is an array, the
asinh
function will be applied to each element and the result returned
as an array.
Compute the arc-tangent of a number
y = atan (x)
The atan
function computes the arc-tangent of a number and
returns the result. If its argument is an array, the
atan
function will be applied to each element and the result returned
as an array.
Compute the arc-tangent of the ratio of two variables
z = atan2 (y, x)
The atan2
function computes the arc-tangent of the ratio
y/x
and returns the result as a value that has the
proper sign for the quadrant where the point (x,y) is located. The
returned value z
will satisfy (-PI < z <= PI). If either of the
arguments is an array, an array of the corresponding values will be returned.
Compute the inverse-tanh of a number
y = atanh (x)
The atanh
function computes the inverse hyperbolic tangent of a number and
returns the result. If its argument is an array, the
atanh
function will be applied to each element and the result returned
as an array.
Round x up to the nearest integral value
y = ceil (x)
This function rounds its numeric argument up to the nearest integral value. If the argument is an array, the corresponding array will be returned.
Compute the complex conjugate of a number
z1 = Conj (z)
The Conj
function returns the complex conjugate of a number.
If its argument is an array, the Conj
function will be applied to each
element and the result returned as an array.
Compute the cosine of a number
y = cos (x)
The cos
function computes the cosine of a number and
returns the result. If its argument is an array, the
cos
function will be applied to each element and the result returned
as an array.
Compute the hyperbolic cosine of a number
y = cosh (x)
The cosh
function computes the hyperbolic cosine of a number and
returns the result. If its argument is an array, the
cosh
function will be applied to each element and the result returned
as an array.
Compute the absolute difference of two values
y = _diff (x, y)
The _diff
function returns a floating point number equal to
the absolute value of the difference of its two arguments.
If either argument is an array, an array of the corresponding values
will be returned.
Compute the exponential of a number
y = exp (x)
The exp
function computes the exponential of a number and
returns the result. If its argument is an array, the
exp
function will be applied to each element and the result returned
as an array.
Compute exp(x)-1
y = expm1(x)
The expm1
function computes exp(x)-1
and returns the
result. If its argument is an array, the expm1
function will
be applied to each element and the results returned as an array.
This function should be called whenever x
is close to 0 to
avoid the numerical error that would arise in a naive computation of
exp(x)-1
.
Test the approximate equality of two numbers
Char_Type feqs (a, b [,reldiff [,absdiff]])
This function compares two floating point numbers a
and
b
, and returns a non-zero value if they are equal to within a
specified tolerance; otherwise 0 will be returned. If either is an
array, a corresponding boolean array will be returned.
The tolerances are specified as relative and absolute differences via
the optional third and fourth arguments. If no optional arguments
are present, the tolerances default to reldiff=0.01
and
absdiff=1e-6
. If only the relative difference has been
specified, the absolute difference (absdiff
) will be taken to
be 0.0.
For the case when |b|>=|a|
, a
and b
are
considered to be equal to within the specified tolerances if either
|b-a|<=absdiff
or |b-a|/|b|<=reldiff
is true.
Compare two numbers using specified tolerances.
Char_Type fgteqs (a, b [,reldiff [,absdiff]])
This function is functionally equivalent to:
(a >= b) or feqs(a,b,...)
See the documentation of feqs
for more information.
Round x down to the nearest integer
y = floor (x)
This function rounds its numeric argument down to the nearest integral value. If the argument is an array, the corresponding array will be returned.
Compare two numbers using specified tolerances.
Char_Type flteqs (a, b [,reldiff [,absdiff]])
This function is functionally equivalent to:
(a <= b) or feqs(a,b,...)
See the documentation of feqs
for more information.
Test the approximate inequality of two numbers
Char_Type fneqs (a, b [,reldiff [,absdiff]])
This function is functionally equivalent to:
not fneqs(a,b,...)
See the documentation of feqs
for more information.
Get the format for printing floating point values.
String_Type get_float_format ()
The get_float_format
retrieves the format string used for
printing single and double precision floating point numbers. See the
documentation for the set_float_format
function for more
information about the format.
Compute sqrt(x1^2+x2^2+...+xN^2)
r = hypot (x1 [,x2,..,xN])
If given two or more arguments, x1,...,xN
, the hypot
function computes the quantity sqrt(x1^2+...+xN^2)
using an
algorithm that tries to avoid arithmetic overflow. If any of the
arguments is an array, an array of the corresponding values will be
returned.
If given a single array argument x
, the hypot
function
computes sqrt(sumsq(x))
, where sumsq(x)
computes
the sum of the squares of the elements of x
.
A vector in Euclidean 3 dimensional space may be represented by an
array of three values representing the components of the vector in
some orthogonal cartesian coordinate system. Then the length of the
vector may be computed using the hypot
function, e.g.,
A = [2,3,4];
len_A = hypot (A);
The dot-product or scalar-product between two such vectors A
and B
may be computed using the sum(A*B)
. It is well
known that this is also equal to the product of the lengths of the
two vectors and the cosine of the angle between them. Hence, the
angle between the vectors A
and B
may be computed using
ahat = A/hypot(A);
bhat = B/hypot(B);
theta = acos(\sum(ahat*bhat));
Here, ahat
and bhat
are the unit vectors associated
with the vectors A
and B
, respectively.
Unfortunately, the above method for computing the angle between the
vectors is numerically unstable when A
and B
are
nearly parallel. An alternative method is to use:
ahat = A/hypot(A);
bhat = B/hypot(B);
ab = sum(ahat*bhat);
theta = atan2 (hypot(bhat - ab*ahat), ab);
Compute the imaginary part of a number
i = Imag (z)
The Imag
function returns the imaginary part of a number.
If its argument is an array, the Imag
function will be applied to each
element and the result returned as an array.
Test for infinity
y = isinf (x)
This function returns 1 if x corresponds to an IEEE infinity, or 0 otherwise. If the argument is an array, an array of the corresponding values will be returned.
isnan
y = isnan (x)
This function returns 1 if x corresponds to an IEEE NaN (Not a Number), or 0 otherwise. If the argument is an array, an array of the corresponding values will be returned.
Test if a number is less than 0
Char_Type _isneg(x)
This function returns 1 if a number is less than 0, and zero
otherwise. If the argument is an array, then the corresponding
array of boolean (Char_Type
) values will be returned.
Test if a number is greater than or equal to 0
Char_Type _isnonneg(x)
This function returns 1 if a number is greater than or equal to 0,
and zero otherwise. If the argument is an array, then the
corresponding array of boolean (Char_Type
) values will be
returned.
Test if a number is greater than 0
Char_Type _ispos(x)
This function returns 1 if a number is greater than 0, and zero
otherwise. If the argument is an array, then the corresponding
array of boolean (Char_Type
) values will be returned.
Compute the logarithm of a number
y = log (x)
The log
function computes the natural logarithm of a number and
returns the result. If its argument is an array, the
log
function will be applied to each element and the result returned
as an array.
Compute the base-10 logarithm of a number
y = log10 (x)
The log10
function computes the base-10 logarithm of a number and
returns the result. If its argument is an array, the
log10
function will be applied to each element and the result returned
as an array.
Compute the logarithm of 1 plus a number
y = log1p (x)
The log1p
function computes the natural logarithm of 1.0 plus
x
returns the result. If its argument is an array, the
log1p
function will be applied to each element and the results
returned as an array.
This function should be used instead of log(1+x)
to avoid
numerical errors whenever x
is close to 0.
Compute the maximum of two or more numeric values
z = _max (x1,...,xN)
The _max
function returns a floating point number equal to
the maximum value of its arguments. If any of the argiments are
arrays (of equal length), an array of the corresponding values will
be returned.
This function returns a floating point result even when the arguments are integers.
Compute the minimum of two or more numeric values
z = _min (x1,...,xN)
The _min
function returns a floating point number equal to
the minimum value of its arguments. If any of the argiments are
arrays (of equal length), an array of the corresponding values will
be returned.
This function returns a floating point result even when the arguments are integers.
Multiply a number by 2
y = mul2(x)
The mul2
function multiplies an arithmetic type by two and
returns the result. If its argument is an array, a new array will
be created whose elements are obtained from the original array by
using the mul2
function.
Round to the nearest integer
i = nint(x)
The nint
rounds its argument to the nearest integer and
returns the result. If its argument is an array, a new array will
be created whose elements are obtained from the original array
elements by using the nint
function.
Evaluate a polynomial
Double_Type polynom([a0,a1,...aN], x [,use_factorial])
The polynom
function returns the value of the polynomial expression
a0 + a1*x + a2*x^2 + ... + aN*x^N
where the coefficients are given by an array of values
[a0,...,aN]
. If x
is an array, the function will
return a corresponding array. If the value of the optional
use_factorial
parameter is non-zero, then each term in the sum
will be normalized by the corresponding factorial, i.e.,
a0/0! + a1*x/1! + a2*x^2/2! + ... + aN*x^N/N!
Prior to version 2.2, this function had a different calling syntax and and was less useful.
The polynom
function does not yet support complex-valued
coefficients.
For the case of a scalar value of x
and a small degree
polynomial, it is more efficient to use an explicit expression.
Compute the real part of a number
r = Real (z)
The Real
function returns the real part of a number. If its
argument is an array, the Real
function will be applied to
each element and the result returned as an array.
Round to the nearest integral value
y = round (x)
This function rounds its argument to the nearest integral value and returns it as a floating point result. If the argument is an array, an array of the corresponding values will be returned.
Set the format for printing floating point values.
set_float_format (String_Type fmt)
The set_float_format
function is used to set the floating
point format to be used when floating point numbers are printed.
The routines that use this are the traceback routines and the
string
function, any anything based upon the string
function. The default value is "%S"
, which causes the number
to be displayed with enough significant digits such that
x==atof(string(x))
.
set_float_format ("%S"); % default
s = string (PI); % --> s = "3.141592653589793"
set_float_format ("%16.10f");
s = string (PI); % --> s = "3.1415926536"
set_float_format ("%10.6e");
s = string (PI); % --> s = "3.141593e+00"
Compute the sign of a number
y = sign(x)
The sign
function returns the sign of an arithmetic type. If
its argument is a complex number (Complex_Type
), the
sign
will be applied to the imaginary part of the number. If
the argument is an array, a new array will be created whose elements
are obtained from the original array by using the sign
function.
When applied to a real number or an integer, the sign
function
returns -1
, 0
, or +1
according to whether the number is
less than zero, equal to zero, or greater than zero, respectively.
Compute the sine of a number
y = sin (x)
The sin
function computes the sine of a number and
returns the result. If its argument is an array, the
sin
function will be applied to each element and the result returned
as an array.
Compute the sine and cosine of a number
(s, c) = sincos (x)
The sincos
function computes the sine and cosine of a
number and returns the result. If its argument is an array,
the sincos
function will be applied to each element
and the result returned as an array.
Compute the hyperbolic sine of a number
y = sinh (x)
The sinh
function computes the hyperbolic sine of a number and
returns the result. If its argument is an array, the
sinh
function will be applied to each element and the result returned
as an array.
Compute the square of a number
y = sqr(x)
The sqr
function returns the square of an arithmetic type. If its
argument is a complex number (Complex_Type
), then it returns
the square of the modulus. If the argument is an array, a new array
will be created whose elements are obtained from the original array
by using the sqr
function.
For real scalar numbers, using x*x
instead of sqr(x)
will result in faster executing code. However, if x
is an
array, then sqr(x)
will execute faster.
Compute the square root of a number
y = sqrt (x)
The sqrt
function computes the square root of a number and
returns the result. If its argument is an array, the
sqrt
function will be applied to each element and the result returned
as an array.
Compute the tangent of a number
y = tan (x)
The tan
function computes the tangent of a number and
returns the result. If its argument is an array, the
tan
function will be applied to each element and the result returned
as an array.
Compute the hyperbolic tangent of a number
y = tanh (x)
The tanh
function computes the hyperbolic tangent of a number and
returns the result. If its argument is an array, the
tanh
function will be applied to each element and the result returned
as an array.