octave: Predicates for Numeric Objects

 
 4.8 Predicates for Numeric Objects
 ==================================
 
 Since the type of a variable may change during the execution of a
 program, it can be necessary to do type checking at run-time.  Doing
 this also allows you to change the behavior of a function depending on
 the type of the input.  As an example, this naive implementation of
 ‘abs’ returns the absolute value of the input if it is a real number,
 and the length of the input if it is a complex number.
 
      function a = abs (x)
        if (isreal (x))
          a = sign (x) .* x;
        elseif (iscomplex (x))
          a = sqrt (real(x).^2 + imag(x).^2);
        endif
      endfunction
 
    The following functions are available for determining the type of a
 variable.
 
  -- : isnumeric (X)
      Return true if X is a numeric object, i.e., an integer, real, or
      complex array.
 
      Logical and character arrays are not considered to be numeric.
 
DONTPRINTYET       See also: Seeisinteger XREFisinteger, *noteisfloat:
DONTPRINTYET DONTPRINTYET       See also: Seeisinteger XREFisinteger, Seeisfloat

      XREFisfloat, Seeisreal XREFisreal, *noteiscomplex:
DONTPRINTYET DONTPRINTYET DONTPRINTYET       See also: Seeisinteger XREFisinteger, Seeisfloat

      XREFisfloat, Seeisreal XREFisreal, Seeiscomplex

      XREFiscomplex, Seeislogical XREFislogical, *noteischar:
DONTPRINTYET DONTPRINTYET DONTPRINTYET       See also: Seeisinteger XREFisinteger, Seeisfloat

      XREFisfloat, Seeisreal XREFisreal, Seeiscomplex

      XREFiscomplex, Seeislogical XREFislogical, Seeischar

      XREFischar, Seeiscell XREFiscell, Seeisstruct XREFisstruct,
      Seeisa XREFisa.
 
  -- : islogical (X)
  -- : isbool (X)
      Return true if X is a logical object.
 
DONTPRINTYET       See also: Seeisfloat XREFisfloat, *noteisinteger:
DONTPRINTYET DONTPRINTYET       See also: Seeisfloat XREFisfloat, Seeisinteger

      XREFisinteger, Seeischar XREFischar, *noteisnumeric:
DONTPRINTYET DONTPRINTYET       See also: Seeisfloat XREFisfloat, Seeisinteger

      XREFisinteger, Seeischar XREFischar, Seeisnumeric

      XREFisnumeric, Seeisa XREFisa.
 
  -- : isfloat (X)
      Return true if X is a floating-point numeric object.
 
      Objects of class double or single are floating-point objects.
 
      See also: Seeisinteger XREFisinteger, Seeischar XREFischar,
      Seeislogical XREFislogical, Seeisnumeric XREFisnumeric,
      Seeisa XREFisa.
 
  -- : isreal (X)
      Return true if X is a non-complex matrix or scalar.
 
      For compatibility with MATLAB, this includes logical and character
      matrices.
 
DONTPRINTYET       See also: Seeiscomplex XREFiscomplex, *noteisnumeric:
DONTPRINTYET       See also: Seeiscomplex XREFiscomplex, Seeisnumeric

      XREFisnumeric, Seeisa XREFisa.
 
  -- : iscomplex (X)
      Return true if X is a complex-valued numeric object.
 
      See also: Seeisreal XREFisreal, Seeisnumeric XREFisnumeric,
DONTPRINTYET       Seeislogical XREFislogical, Seeischar XREFischar, *noteDONTPRINTYET       Seeislogical XREFislogical, Seeischar XREFischar, See
      isfloat XREFisfloat, Seeisa XREFisa.
 
  -- : ismatrix (A)
      Return true if A is a 2-D array.
 
DONTPRINTYET       See also: Seeisscalar XREFisscalar, *noteisvector:
DONTPRINTYET DONTPRINTYET       See also: Seeisscalar XREFisscalar, Seeisvector

      XREFisvector, Seeiscell XREFiscell, *noteisstruct:
DONTPRINTYET DONTPRINTYET       See also: Seeisscalar XREFisscalar, Seeisvector

      XREFisvector, Seeiscell XREFiscell, Seeisstruct

      XREFisstruct, Seeissparse XREFissparse, Seeisa XREFisa.
 
  -- : isvector (X)
      Return true if X is a vector.
 
      A vector is a 2-D array where one of the dimensions is equal to 1.
      As a consequence a 1x1 array, or scalar, is also a vector.
 
DONTPRINTYET       See also: Seeisscalar XREFisscalar, *noteismatrix:
DONTPRINTYET DONTPRINTYET       See also: Seeisscalar XREFisscalar, Seeismatrix

      XREFismatrix, Seesize XREFsize, Seerows XREFrows, *noteDONTPRINTYET DONTPRINTYET       See also: Seeisscalar XREFisscalar, Seeismatrix

      XREFismatrix, Seesize XREFsize, Seerows XREFrows, See
      columns XREFcolumns, Seelength XREFlength.
 
  -- : isrow (X)
      Return true if X is a row vector 1xN with non-negative N.
 
DONTPRINTYET       See also: Seeiscolumn XREFiscolumn, *noteisscalar:
DONTPRINTYET DONTPRINTYET       See also: Seeiscolumn XREFiscolumn, Seeisscalar

      XREFisscalar, Seeisvector XREFisvector, *noteismatrix:
DONTPRINTYET DONTPRINTYET       See also: Seeiscolumn XREFiscolumn, Seeisscalar

      XREFisscalar, Seeisvector XREFisvector, Seeismatrix

      XREFismatrix.
 
  -- : iscolumn (X)
      Return true if X is a column vector Nx1 with non-negative N.
 
      See also: Seeisrow XREFisrow, Seeisscalar XREFisscalar,
      Seeisvector XREFisvector, Seeismatrix XREFismatrix.
 
  -- : isscalar (X)
      Return true if X is a scalar.
 
DONTPRINTYET       See also: Seeisvector XREFisvector, *noteismatrix:
DONTPRINTYET       See also: Seeisvector XREFisvector, Seeismatrix

      XREFismatrix.
 
  -- : issquare (X)
      Return true if X is a square matrix.
 
DONTPRINTYET       See also: Seeisscalar XREFisscalar, *noteisvector:
DONTPRINTYET       See also: Seeisscalar XREFisscalar, Seeisvector

      XREFisvector, Seeismatrix XREFismatrix, Seesize XREFsize.
 
  -- : issymmetric (A)
  -- : issymmetric (A, TOL)
      Return true if A is a symmetric matrix within the tolerance
      specified by TOL.
 
      The default tolerance is zero (uses faster code).
 
      Matrix A is considered symmetric if ‘norm (A - A.', Inf) / norm (A,
      Inf) < TOL’.
 
DONTPRINTYET       See also: Seeishermitian XREFishermitian, *noteisdefinite:
DONTPRINTYET       See also: Seeishermitian XREFishermitian, Seeisdefinite

      XREFisdefinite.
 
  -- : ishermitian (A)
  -- : ishermitian (A, TOL)
      Return true if A is Hermitian within the tolerance specified by
      TOL.
 
      The default tolerance is zero (uses faster code).
 
      Matrix A is considered symmetric if ‘norm (A - A', Inf) / norm (A,
      Inf) < TOL’.
 
DONTPRINTYET       See also: Seeissymmetric XREFissymmetric, *noteisdefinite:
DONTPRINTYET       See also: Seeissymmetric XREFissymmetric, Seeisdefinite

      XREFisdefinite.
 
  -- : isdefinite (A)
  -- : isdefinite (A, TOL)
      Return 1 if A is symmetric positive definite within the tolerance
      specified by TOL or 0 if A is symmetric positive semidefinite.
      Otherwise, return -1.
 
      If TOL is omitted, use a tolerance of ‘100 * eps * norm (A, "fro")’
 
DONTPRINTYET       See also: Seeissymmetric XREFissymmetric, *noteishermitian:
DONTPRINTYET       See also: Seeissymmetric XREFissymmetric, Seeishermitian

      XREFishermitian.
 
  -- : isbanded (A, LOWER, UPPER)
      Return true if A is a matrix with entries confined between LOWER
      diagonals below the main diagonal and UPPER diagonals above the
      main diagonal.
 
      LOWER and UPPER must be non-negative integers.
 
DONTPRINTYET       See also: Seeisdiag XREFisdiag, Seeistril XREFistril, *noteDONTPRINTYET       See also: Seeisdiag XREFisdiag, Seeistril XREFistril, See
      istriu XREFistriu, Seebandwidth XREFbandwidth.
 
  -- : isdiag (A)
      Return true if A is a diagonal matrix.
 
      See also: Seeisbanded XREFisbanded, Seeistril XREFistril,
DONTPRINTYET       Seeistriu XREFistriu, Seediag XREFdiag, *notebandwidth:
DONTPRINTYET       Seeistriu XREFistriu, Seediag XREFdiag, Seebandwidth

      XREFbandwidth.
 
  -- : istril (A)
      Return true if A is a lower triangular matrix.
 
      A lower triangular matrix has nonzero entries only on the main
      diagonal and below.
 
      See also: Seeistriu XREFistriu, Seeisbanded XREFisbanded,
DONTPRINTYET       Seeisdiag XREFisdiag, Seetril XREFtril, *notebandwidth:
DONTPRINTYET       Seeisdiag XREFisdiag, Seetril XREFtril, Seebandwidth

      XREFbandwidth.
 
  -- : istriu (A)
      Return true if A is an upper triangular matrix.
 
      An upper triangular matrix has nonzero entries only on the main
      diagonal and above.
 
      See also: Seeisdiag XREFisdiag, Seeisbanded XREFisbanded,
DONTPRINTYET       Seeistril XREFistril, Seetriu XREFtriu, *notebandwidth:
DONTPRINTYET       Seeistril XREFistril, Seetriu XREFtriu, Seebandwidth

      XREFbandwidth.
 
  -- : isprime (X)
      Return a logical array which is true where the elements of X are
      prime numbers and false where they are not.
 
      A prime number is conventionally defined as a positive integer
      greater than 1 (e.g., 2, 3, ...) which is divisible only by itself
      and 1.  Octave extends this definition to include both negative
      integers and complex values.  A negative integer is prime if its
      positive counterpart is prime.  This is equivalent to ‘isprime (abs
      (x))’.
 
      If ‘class (X)’ is complex, then primality is tested in the domain
      of Gaussian integers
      (<http://en.wikipedia.org/wiki/Gaussian_integer>).  Some
      non-complex integers are prime in the ordinary sense, but not in
      the domain of Gaussian integers.  For example, 5 = (1+2i)*(1-2i)
      shows that 5 is not prime because it has a factor other than itself
      and 1.  Exercise caution when testing complex and real values
      together in the same matrix.
 
      Examples:
 
           isprime (1:6)
               ⇒ [0, 1, 1, 0, 1, 0]
 
           isprime ([i, 2, 3, 5])
               ⇒ [0, 0, 1, 0]
 
      Programming Note: ‘isprime’ is appropriate if the maximum value in
      X is not too large (< 1e15).  For larger values special purpose
      factorization code should be used.
 
      Compatibility Note: MATLAB does not extend the definition of prime
      numbers and will produce an error if given negative or complex
      inputs.
 
DONTPRINTYET       See also: Seeprimes XREFprimes, Seefactor XREFfactor, *noteDONTPRINTYET       See also: Seeprimes XREFprimes, Seefactor XREFfactor, See
      gcd XREFgcd, Seelcm XREFlcm.
 
    If instead of knowing properties of variables, you wish to know which
 variables are defined and to gather other information about the
 workspace itself, SeeStatus of Variables.