Next: , Up: Arithmetic


19.1 Utility Functions

The following functions are available for working with complex numbers. Each expects a single argument. They are called mapping functions because when given a matrix argument, they apply the given function to each element of the matrix.

— Mapping Function: ceil (x)

Return the smallest integer not less than x. If x is complex, return ceil (real (x)) + ceil (imag (x)) * I.

— Mapping Function: exp (x)

Compute the exponential of x. To compute the matrix exponential, see Linear Algebra.

— Mapping Function: fix (x)

Truncate x toward zero. If x is complex, return fix (real (x)) + fix (imag (x)) * I.

— Mapping Function: floor (x)

Return the largest integer not greater than x. If x is complex, return floor (real (x)) + floor (imag (x)) * I.

— Loadable Function: g = gcd (a1, ...)
— Loadable Function: [g, v1, ...] = gcd (a1, ...)

If a single argument is given then compute the greatest common divisor of the elements of this argument. Otherwise if more than one argument is given all arguments must be the same size or scalar. In this case the greatest common divisor is calculated for element individually. All elements must be integers. For example,

          gcd ([15, 20])
              =>  5
     

and

          gcd ([15, 9], [20 18])
              =>  5  9
     

Optional return arguments v1, etc, contain integer vectors such that,

          g = v1 .* a1 + v2 .* a2 + ...
     

For backward compatiability with previous versions of this function, when all arguments are scalr, a single return argument v1 containing all of the values of v1, ... is acceptable.

     
     
See also: lcm, min, max, ceil, floor.

— Mapping Function: lcm (x, ...)

Compute the least common multiple of the elements elements of x, or the list of all the arguments. For example,

          lcm (a1, ..., ak)
     

is the same as

          lcm ([a1, ..., ak]).
     

All elements must be the same size or scalar.

     
     
See also: gcd, min, max, ceil, floor.

— Mapping Function: log (x)

Compute the natural logarithm for each element of x. To compute the matrix logarithm, see Linear Algebra.

     
     
See also: log2, log10, logspace, exp.

— Mapping Function: log10 (x)

Compute the base-10 logarithm for each element of x.

     
     
See also: log, log2, logspace, exp.

— Mapping Function: log2 (x)
— Mapping Function: [f, e] = log2 (x)

Compute the base-2 logarithm of x. With two outputs, returns f and e such that 1/2 <= abs(f) < 1 and x = f * 2^e.

     
     
See also: log, log10, logspace, exp.

— Mapping Function: max (x, y, dim)
— Mapping Function: [w, iw] = max (x)

For a vector argument, return the maximum value. For a matrix argument, return the maximum value from each column, as a row vector, or over the dimension dim if defined. For two matrices (or a matrix and scalar), return the pair-wise maximum. Thus,

          max (max (x))
     

returns the largest element of x, and

          max (2:5, pi)
              =>  3.1416  3.1416  4.0000  5.0000
     

compares each element of the range 2:5 with pi, and returns a row vector of the maximum values.

For complex arguments, the magnitude of the elements are used for comparison.

If called with one input and two output arguments, max also returns the first index of the maximum value(s). Thus,

          [x, ix] = max ([1, 3, 5, 2, 5])
              =>  x = 5
                  ix = 3
     

— Mapping Function: min (x, y, dim)
— Mapping Function: [w, iw] = min (x)

For a vector argument, return the minimum value. For a matrix argument, return the minimum value from each column, as a row vector, or over the dimension dim if defined. For two matrices (or a matrix and scalar), return the pair-wise minimum. Thus,

          min (min (x))
     

returns the smallest element of x, and

          min (2:5, pi)
              =>  2.0000  3.0000  3.1416  3.1416
     

compares each element of the range 2:5 with pi, and returns a row vector of the minimum values.

For complex arguments, the magnitude of the elements are used for comparison.

If called with one input and two output arguments, min also returns the first index of the minimum value(s). Thus,

          [x, ix] = min ([1, 3, 0, 2, 5])
              =>  x = 0
                  ix = 3
     

— Mapping Function: mod (x, y)

Compute modulo function, using

          x - y .* floor (x ./ y)
     

Note that this handles negative numbers correctly: mod (-1, 3) is 2, not -1 as rem (-1, 3) returns. Also, mod (x, 0) returns x.

An error message is printed if the dimensions of the arguments do not agree, or if either of the arguments is complex.

     
     
See also: rem, round.

— Function File: nextpow2 (x)

If x is a scalar, returns the first integer n such that 2^n >= abs (x).

If x is a vector, return nextpow2 (length (x)).

     
     
See also: pow2.

— Mapping Function: pow2 (x)
— Mapping Function: pow2 (f, e)

With one argument, computes 2 .^ x for each element of x. With two arguments, returns f .* (2 .^ e).

     
     
See also: nextpow2.

— Mapping Function: rem (x, y)

Return the remainder of x / y, computed using the expression

          x - y .* fix (x ./ y)
     

An error message is printed if the dimensions of the arguments do not agree, or if either of the arguments is complex.

     
     
See also: mod, round.

— Mapping Function: round (x)

Return the integer nearest to x. If x is complex, return round (real (x)) + round (imag (x)) * I.

     
     
See also: rem.

— Mapping Function: sign (x)

Compute the signum function, which is defined as

                     -1, x < 0;
          sign (x) =  0, x = 0;
                      1, x > 0.
     

For complex arguments, sign returns x ./ abs (x).

— Mapping Function: sqrt (x)

Compute the square root of x. If x is negative, a complex result is returned. To compute the matrix square root, see Linear Algebra.