GraphExpert Professional 1.6.0 documentation

Appendix A: Math Functions

This section documents the math functions that are available for use in GraphExpert Professional functions and data transformations.

All functions below, unless otherwise stated, work on either scalars (a single number) or an array (a vector). If an array is passed to any of these functions, the function is applied elementwise to each member of the array.

Constants

pi

The mathematical constant 3.14159….

exp1

The mathematical constant 2.71828…..

Transcendental Functions

acos(x)

Trigonometric inverse cosine. The inverse of cos so that, if y = cos(x), then x = acos(y). The domain is [-1, 1].

acos is a multivalued function: for each x there are infinitely many numbers z such that cos(z) = x. The convention is to return the angle z whose real part lies in [0, pi].

The inverse cos is also known as arccos or cos^-1.

acosh(x)

Inverse hyperbolic cosine.

acosh is a multivalued function: for each x there are infinitely many numbers z such that cosh(z) = x. The convention is to return the z whose imaginary part lies in [-pi, pi] and the real part in [0, inf].

asin(x)

Inverse sine. The inverse sine of each element in x, in radians and in the closed interval [-pi/2, pi/2].

arcsin is a multivalued function: for each x there are infinitely many numbers z such that sin(z) = x. The convention is to return the angle z whose real part lies in [-pi/2, pi/2].

The inverse sine is also known as arcsin or sin^{-1}.

asinh(x)

Inverse hyperbolic sine.

arcsinh is a multivalued function: for each x there are infinitely many numbers z such that sinh(z) = x. The convention is to return the z whose imaginary part lies in [-pi/2, pi/2].

The inverse hyperbolic sine is also known as arcsinh or sinh^-1.

atan(x)

Trigonometric inverse tangent. The inverse of tan, so that if y = tan(x) then x = atan(y).

atan is a multi-valued function: for each x there are infinitely many numbers z such that tan(z) = x. The convention is to return the angle z whose real part lies in [-pi/2, pi/2].

The inverse tangent is also known as arctan or tan^{-1}.

atan2(y,x)

Arc tangent of y/x choosing the quadrant correctly.

The quadrant (i.e., branch) is chosen so that arctan2(y, x) is the signed angle in radians between the ray ending at the origin and passing through the point (1,0), and the ray ending at the origin and passing through the point (x2, x1). By IEEE convention, this function is defined for x = +/-0 and for either or both of y and x = +/-inf (see Notes for specific values).

Returns angle in radians, in the range [-pi, pi].

atanh(x)

Inverse hyperbolic tangent.

arctanh is a multivalued function: for each x there are infinitely many numbers z such that tanh(z) = x. The convention is to return the z whose imaginary part lies in [-pi/2, pi/2].

The inverse hyperbolic tangent is also known as arctanh or tanh^-1.

cos(x)

Trigonometric cosine.

cosh(x)

Hyperbolic cosine. Equivalent to 1/2 * (exp(x) + exp(-x)).

erf(x)

Error function of x defined as

\textrm{erf}(x) = \frac{2}{\sqrt{\pi}} \int_0^x{e^{-t^2}dt}

erfc(x)

Returns

\textrm{erfc}(x) = 1 - \textrm{erf}(x) = \frac{2}{\sqrt{\pi}} \int_x^{\infty}{e^{-t^2}dt}

exp(x)

Calculate the exponential.

The irrational number e is also known as Euler’s number. It is approximately 2.718281, and is the base of the natural logarithm, ln (this means that, if x = \ln y = \log_e y, then e^x = y. For real input, exp(x) is always positive.

ln(x)

Natural logarithm (synonym for log). The natural logarithm ln is the inverse of the exponential function, so that ln(exp(x)) = x. The natural logarithm is logarithm in base e.

log(x)

Natural logarithm. The natural logarithm log is the inverse of the exponential function, so that log(exp(x)) = x. The natural logarithm is logarithm in base e.

log10(x)

Return the base 10 logarithm. NaNs is returned if x is negative.

sin(x)

Trigonometric sine.

sinh(x)

Hyperbolic sine, element-wise. Equivalent to 1/2 * (exp(x) - exp(-x)).

sqrt(x)

Return the positive square-root. Returns NaN if x is negative.

tan(x)

Compute tangent. Equivalent to sin(x)/cos(x).

tanh(x)

Compute hyperbolic tangent. Equivalent to sinh(x)/cosh(x).

Bessel Functions

bessel_j0(x)

The Bessel function of order 0 at x.

bessel_j1(x)

The Bessel function of order 1 at x.

bessel_jn(n,x)

Bessel function of integer or real order n.

bessel_y0(x)

The Bessel function of the second kind of order 0 at x.

bessel_y1(x)

The Bessel function of the second kind of order 1 at x.

bessel_yn(n,x)

Bessel function of the second kind of integer or real order n at x.

bessel_i0(x)

Modified Bessel function of the first kind, order 0.

bessel_i1(x)

Modified Bessel function of order 1 at x.

bessel_k0(x)

Modified Bessel function of the second kind (sometimes called the third kind) of order 0 at x.

bessel_k1(x)

Modified Bessel function of the second kind (sometimes called the third kind) of order 1 at x.

bessel_kn(n,x)

Modified Bessel function of the second kind (sometimes called the third kind) for integer or real order n at x.

bessel_i0e(x)

Exponentially scaled modified Bessel function of order 0 at x. bessel_i0e(x) = exp(-|x|) * bessel_i0(x).

bessel_i1e(x)

Exponentially scaled modified Bessel function of order 0 at x. bessel_i1e(x) = exp(-|x|) * bessel_i1(x).

bessel_k0e(x)

Exponentially scaled modified Bessel function of the second kind (sometimes called the third kind) of order 0 at x. bessel_k0e(x) = exp(x) * bessel_k0(x).

bessel_k1e(x)

Exponentially scaled modified Bessel function of the second kind (sometimes called the third kind) of order 1 at x. bessel_k1e(x) = exp(x) * bessel_k1(x).

bessel_jvp(n,x,i)

Return the ith derivative of bessel_jn(n,x).

bessel_yvp(n,x,i)

Return the nth derivative of bessel_yn(n,x).

bessel_kvp(n,x,i)

Return the nth derivative of bessel_kn(n,x).

bessel_ivp(n,x,i)

Return the nth derivative of bessel_in(n,x).

Comparison Functions

maximum(a,b)

Element-wise maximum of array elements; compares two arrays and returns a new array containing the elementwise maxima. If one of the elements is a NaN, that element is returned.

minimum(a,b)

Element-wise minimum of array elements; compares two arrays and returns a new array containing the elementwise minima. If one of the elements is a NaN, that element is returned.

max(array)

Return the maximum of an array (returns a scalar). Optionally, the keyword ‘axis’ can be given to specify, for a 2D dataset, if the max should be taken down the columns (axis=0) or across the rows(axis=1).

min(array)

Return the minimum of an array (returns a scalar). Optionally, the keyword ‘axis’ can be given to specify, for a 2D dataset, if the min should be taken down the columns (axis=0) or across the rows(axis=1).

Miscellaneous Functions

abs(x)

Calculate the absolute value.

ceil(x)

Returns the ceiling of the input. The ceil of the scalar x is the smallest integer i, such that i >= x.

copysign(x1,x2)

Change the sign of x1 to that of x2.

degrees(x)

Convert angles from radians to degrees.

factorial(n)

Take the factorial of an integer n.

floor(x)

Return the floor of the input. The floor of the scalar x is the largest integer i, such that i <= x.

Some spreadsheet programs calculate the “floor-towards-zero”, in other words floor(-2.5) == -2. Here, however, we use the a definition of floor such that floor(-2.5) == -3.

fmod(x1,x2)

Return the remainder of division. Returns the remainder of the division of x1 by x2.

The result of the modulo operation for negative dividend and divisors is bound by conventions. In fmod, the sign of the remainder is the sign of the dividend. In remainder, the sign of the divisor does not affect the sign of the result.

hypot(x1,x2)

Given the “legs” of a right triangle, return its hypotenuse. Equivalent to sqrt(x1**2 + x2**2).

isinf(x)

Test for positive or negative infinity.

isnan(x)

Test for Not a Number (NaN).

legendre(n,x)

Legendre function of order n evaluated at x. Orthogonal over [1,1] with weighting function 1.

lstsq_solve(A,B)

Solve a least squares problem, where A is a rectangular matrix. Returns a tuple of four quantities: x (the least squares solution), residuals (array ncol long), rank (integer indicating the effective rank of A), and s (the singular values of a). Common usage is as follows:

(soln,resid,rank,s) = solve_lstsq(A,B)

Can throw an exception if the computation is too ill-conditioned.

sh_legendre(n,x)

Shifted Legendre function of order n evaluated at x. Orthogonal over [0,1] with weighting function 1.

radians(x)

Convert angles from degrees to radians.

round(a,number_of_decimals)

Round an array to a given number of decimals. number_of_decimals is an integer denoting the number of decimal places to retain.

special_beta(p,q)

Returns

\beta(p,q) = \Gamma(p) \Gamma(q) / \Gamma(p+q)

special_lambda(nu,x)

Returns

\Lambda_\nu (x) = \frac{J_{\nu}(x)}{\left (\frac{1}{2} x \right )^\nu}

The Bessel function used here is the same as special_jn(n,x).

special_gamma(x)

Gamma function. The gamma function is often referred to as the generalized factorial since x*gamma(x) = gamma(x+1) and gamma(n+1) = n! for natural number n.

Note that the domain is limited to [1.0e-6,10].

trunc(x)

Return the truncated value of the input. The truncated value of the scalar x is the nearest integer i which is closer to zero than x is. In short, the fractional part of the signed number x is discarded.

Array Specific Functions

append(array)

Append values to the end of an array.

array(object)

Create an array from an array_like object, like a Python list or another array.

asarray(object)

Convert the input to an array. a is an array_like object, like a Python list.

arange(start,stop,step)

Return evenly spaced values within a given interval.

Values are generated within the half-open interval [start, stop) (in other words, the interval including start but excluding stop).

average(a)

Compute the arithmetic average (identical to the mean) of an array (returns a scalar). Optionally, the keyword ‘axis’ can be given to specify, for a 2D dataset, if the average should be taken down the columns (axis=0) or across the rows(axis=1).

\bar x = \frac{\sum_{i=1}^n  x_i}{n}

column_stack((a,b,c,d,…))

Stack 1D arrays as columns into a 2D array.

copy(object)

Return an array copy of the given object.

concatenate((a1,a2,a3,…))

Join a sequence of arrays together.

dot(a,b)

Dot product of two arrays a and b (returns a scalar)

empty(shape)

Return a new array of given shape, without initializing entries. If the new array should be one dimensional, just an integer will suffice for the shape. If the new array should be multidimensional, then my_array = empty((n,3)) is an appropriate example.

eye(n)

Return a 2-D array with ones on the diagonal and zeros elsewhere.

fliplr(a)

Flip (reverse) an array in the left/right direction (columnwise).

flipud(a)

Flip (reverse) an array in the up/down direction (rowwise).

hstack((a,b,c,d,….))

Stack arrays in sequence horizontally (columnwise)

identity(n)

Return the identity array. The identity array is a square array with ones on the main diagonal.

linspace(start,stop,n)

Return evenly spaced numbers over a specified interval.

Returns n evenly spaced samples, calculated over the interval [start, stop ].

mean(a)

Compute the arithmetic mean (identical to the average) of an array (returns a scalar). Optionally, the keyword ‘axis’ can be given to specify, for a 2D dataset, if the mean should be taken down the columns (axis=0) or across the rows(axis=1).

\bar x = \frac{\sum_{i=1}^n  x_i}{n}

median(a)

Compute the median of an array along the specified column. Returns the median of the array elements. Optionally, the keyword ‘axis’ can be given to specify, for a 2D dataset, if the median should be taken down the columns (axis=0) or across the rows(axis=1).

Given a vector V of length N, the median of V is the middle value of a sorted copy of V, V_sorted - i.e., V_sorted[(N-1)/2], when N is odd. When N is even, it is the average of the two middle values of V_sorted.

nonzero(a)

Returns as an integer array, the indices of the elements are are nonzero. This can be used for indexing into another array.

ones(shape)

Return a new array of given shape, filled with ones. For example, my_array = ones(n) If the new array should be one dimensional, just an integer will suffice for the shape. If the new array should be multidimensional, then my_array = ones((n,3)) is an appropriate example.

ones_like(a)

Returns an array of ones with the same dimension as the given array.

roll(a)

Roll array elements rowwise; rows that roll beyond the last position are reintroduced at the first.

rand(nrow,ncol)

Returns an array of the given dimension (nrow x ncol) and fill it with random samples from a uniform distribution over [0,1).

sort(a)

Return an ascending sorted copy of the array.

standarddev(a)

Return the standard deviation of an array. Optionally, the keyword ‘axis’ can be given to specify, for a 2D dataset, if the standard deviation should be taken down the columns (axis=0) or across the rows(axis=1). Also optionally, the keyword ‘ddof’ can be given to determine the divisor used in the calculations. By default, ddof is 1.

\sigma = \sqrt{\frac{1}{n-DOF} \sum_{i=1}^n \left ( x_i - \bar x \right )^2 }

unique(a)

Find the unique elements of an array; returns the sorted unique elements of an array. Works on only 1D arrays; the array will be flattened if it is not already 1D.

variance(a)

Return the variance of the array. Optionally, the keyword ‘axis’ can be given to specify, for a 2D dataset, if the variance should be taken down the columns (axis=0) or across the rows(axis=1).

vstack((a,b,c,d,….))

Stack arrays in sequence vertically (rowwise).

zeros(shape)

Return a new array of given shape, filled with zeros. For example, my_array = zeros(n). If the new array should be one dimensional, just an integer will suffice for the shape. If the new array should be multidimensional, then my_array = zeros((n,3)) is an appropriate example.

zeros_like(other_array)

Return an array of zeros with the same dimension as a given array. For example, my_array = zeros_like(x)

Logical Functions

array_and(b1,b2)

Applies the logical and operator, elementwise, to two boolean arrays b1 and b2. Returns another boolean array.

array_or(b1,b2)

Applies the logical or operator, elementwise, to two boolean arrays b1 and b2. Returns another boolean array.

array_xor(b1,b2)

Applies the logical xor operator, elementwise, to two boolean arrays b1 and b2. Returns another boolean array.

array_not(b1)

Applies the logical not operator, elementwise, to a boolean array b1. Returns another boolean array.

array_gt(x1,x2)

Returns a boolean array that tests x1 > x2 elementwise.

array_lt(x1,x2)

Returns a boolean array that tests x1 < x2 elementwise.

array_le(x1,x2)

Returns a boolean array that tests x1 <= x2 elementwise.

array_ge(x1,x2)

Returns a boolean array that tests x1 >= x2 elementwise.

array_eq(x1,x2)

Returns a boolean array that tests x1 == x2 elementwise.

array_neq(x1,x2)

Returns a boolean array that tests x1 != x2 elementwise.

array_almost_eq(x1,x2, rtol, atol)

Tests two arrays x1 and x2, elementwise, to see if they are nearly equal within the tolerances specified in rtol and atol. Returns a boolean array. rtol is a relative tolerance, and atol is an absolute tolerance. To determine closeness, the relative difference rtol*abs(b) and the absolute difference atol are added together to compare against the absolute difference between the elements of a and b.