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.
If x is a square matrix, then return the dimension of x. Otherwise, return 0.
See also: size, rows, columns, length, ismatrix, isscalar, isvector.
If x is symmetric within the tolerance specified by tol, then return the dimension of x. Otherwise, return 0. If tol is omitted, use a tolerance equal to the machine precision. Matrix x is considered symmetric if
norm (
x-
x.', inf) / norm (
x, inf) <
tol.See also: size, rows, columns, length, ismatrix, isscalar, issquare, isvector.
Return 1 if x is symmetric positive definite within the tolerance specified by tol or 0 if x is symmetric positive semidefinite. Otherwise, return -1. If tol is omitted, use a tolerance equal to 100 times the machine precision.
See also: issymmetric.