Sysquake Pro – Table of Contents
Sysquake for LaTeX – Table of Contents
Mathematical Functions
abs
Absolute value.
Syntax
x = abs(z)
Description
abs takes the absolute value of each element of its argument. The result is an array of the same size as the argument; each element is non-negative.
Example
abs([2,-3,0,3+4j] 2 3 0 5
See also
angle, sign, real, imag, hypot
acos
Arc cosine.
Syntax
y = acos(x)
Description
acos(x) gives the arc cosine of x, which is complex if x is complex or if abs(x)>1.
Examples
acos(2) 0+1.3170j acos([0,1+2j]) 1.5708 1.1437-1.5286j
See also
acosd acotd acscd asecd asind atand atan2d
Inverse trigonometric functions with angles in degrees.
Syntax
y = acosd(x) y = acotd(x) y = acscd(x) y = asecd(x) y = asind(x) y = atand(x) z = atan2d(y, x)
Description
Inverse trigonometric functions whose name ends with a d give a result expressed in degrees instead of radians.
Examples
acosd(0.5) 60.0000 acos(0.5) * 180 / pi 60.0000
See also
cosd, cotd, cscd, secd, sind, tand, acos, acot, acsc, asec, asin, atan, atan2
acosh
Inverse hyperbolic cosine.
Syntax
y = acosh(x)
Description
acosh(x) gives the inverse hyperbolic cosine of x, which is complex if x is complex or if x<1.
Examples
acosh(2) 1.3170 acosh([0,1+2j]) 0+1.5708j 1.5286+1.1437j
See also
acot
Inverse cotangent.
Syntax
y = acot(x)
Description
acot(x) gives the inverse cotangent of x, which is complex if x is.
See also
acoth
Inverse hyperbolic cotangent.
Syntax
y = acoth(x)
Description
acoth(x) gives the inverse hyperbolic cotangent of x, which is complex if x is complex or is in the range (-1,1).
See also
acsc
Inverse cosecant.
Syntax
y = acsc(x)
Description
acsc(x) gives the inverse cosecant of x, which is complex if x is complex or is in the range (-1,1).
See also
acsch
Inverse hyperbolic cosecant.
Syntax
y = acsch(x)
Description
acsch(x) gives the inverse hyperbolic cosecant of x, which is complex if x is.
See also
angle
Phase angle of a complex number.
Syntax
phi = angle(z)
Description
angle(z) gives the phase of the complex number z, i.e. the angle between the positive real axis and a line joining the origin to z. angle(0) is 0.
Examples
angle(1+3j) 1.2490 angle([0,1,-1]) 0 0 3.1416
See also
asec
Inverse secant.
Syntax
y = asec(x)
Description
asec(x) gives the inverse secant of x, which is complex if x is complex or is in the range (-1,1).
See also
asech
Inverse hyperbolic secant.
Syntax
y = asech(x)
Description
asech(x) gives the inverse hyperbolic secant of x, which is complex if x is complex or strictly negative.
See also
asin
Arc sine.
Syntax
y = asin(x)
Description
asin(x) gives the arc sine of x, which is complex if x is complex or if abs(x)>1.
Examples
asin(0.5) 0.5236 asin(2) 1.5708-1.317j
See also
asinh
Inverse hyperbolic sine.
Syntax
y = asinh(x)
Description
asinh(x) gives the inverse hyperbolic sine of x, which is complex if x is complex.
Examples
asinh(2) 1.4436 asinh([0,1+2j]) 0 1.8055+1.7359j
See also
atan
Arc tangent.
Syntax
y = atan(x)
Description
atan(x) gives the arc tangent of x, which is complex if x is complex.
Example
atan(1) 0.7854
See also
atan2
Direction of a point given by its Cartesian coordinates.
Syntax
phi = atan2(y,x)
Description
atan2(y,x) gives the direction of a point given by its Cartesian coordinates x and y. Imaginary component of complex numbers is ignored. atan2(y,x) is equivalent to atan(y/x) if x>0.
Examples
atan2(1, 1) 0.7854 atan2(-1, -1) -2.3562 atan2(0, 0) 0
See also
atanh
Inverse hyperbolic tangent.
Syntax
y = atanh(x)
Description
atan(x) gives the inverse hyperbolic tangent of x, which is complex if x is complex or if abs(x)>1.
Examples
atanh(0.5) 0.5493 atanh(2) 0.5493 + 1.5708j
See also
beta
Beta function.
Syntax
y = beta(z,w)
Description
beta(z,w) gives the beta function of z and w. Arguments and result are real (imaginary part is discarded). The beta function is defined as
Example
beta(1,2) 0.5
See also
betainc
Incomplete beta function.
Syntax
y = betainc(x,z,w)
Description
betainc(x,z,w) gives the incomplete beta function of x, z and w. Arguments and result are real (imaginary part is discarded). x must be between 0 and 1. The incomplete beta function is defined as
Example
betainc(0.2,1,2) 0.36
See also
betaln
Logarithm of beta function.
Syntax
y = betaln(z,w)
Description
betaln(z,w) gives the logarithm of the beta function of z and w. Arguments and result are real (imaginary part is discarded).
Example
betaln(0.5,2) 0.2877
See also
cart2pol
Cartesian to polar coordinates transform.
Syntax
(phi, r) = cart2pol(x, y) (phi, r, z) = cart2pol(x, y, z)
Description
(phi,r)=cart2pol(x,y) transforms Cartesian coordinates x
and y to polar coordinates phi and r such that
(phi,r,z)=cart2pol(x,y,z) transform Cartesian coordinates to cylindrical coordinates, leaving z unchanged.
Example
(phi, r) = cart2pol(1, 2) phi = 1.1071 r = 2.2361
See also
cart2sph, pol2cart, sph2cart, abs, angle
cart2sph
Cartesian to spherical coordinates transform.
Syntax
(phi, theta, r) = cart2sph(x, y, z)
Description
(phi,theta,r)=cart2sph(x,y,z) transforms Cartesian coordinates x,
y, and z to polar coordinates phi, theta,
and r such that
Example
(phi, theta, r) = cart2sph(1, 2, 3) phi = 1.1071 theta = 0.9303 r = 3.7417
See also
cast
Type conversion.
Syntax
Y = cast(X, type)
Description
cast(X,type) converts the numeric array X to the type given by string type, which can be 'double', 'single', 'int8' or any other signed or unsigned integer type, 'char', or 'logical'. The number value is preserved when possible; conversion to integer types discards most significant bytes. If X is an array, conversion is performed on each element; the result has the same size. The imaginary part, if any, is discarded only with conversions to integer types.
Example
cast(pi, 'int8') 3int8
See also
uint8 and related functions, double, single, typecast
cdf
Cumulative distribution function.
Syntax
y = cdf(distribution,x) y = cdf(distribution,x,a1) y = cdf(distribution,x,a1,a2)
Description
cdf(distribution,x) calculates the integral of a probability density function from
Distribution | Name | Parameters |
---|---|---|
beta | beta | a and b |
Cauchy | cauchy | a and b |
chi | deg. of freedom |
|
chi2 chisquare |
deg. of freedom |
|
gamma | shape |
|
exponential | exp exponential |
mean |
F | f | deg. of freedom |
half-normal | half-normal | |
Laplace | laplace | mean and scale |
lognormal | logn lognormal |
mean (0) and st. dev. (1) |
Nakagami | nakagami | |
normal | norm normal |
mean (0) and st. dev. (1) |
Rayleigh | rayl rayleigh |
b |
Student's T | t student |
deg. of freedom |
uniform | unif uniform |
limits of the range (0 and 1) |
Weibull | weib weibull |
shape k and scale |
Example
cdf('chi2', 2.5, 3) 0.5247 integral(@(x) pdf('chi2',x,3), 0, 2.5, AbsTol=1e-4) 0.5247
See also
ceil
Rounding towards +infinity.
Syntax
y = ceil(x)
Description
ceil(x) gives the smallest integer larger than or equal to x. If the argument is a complex number, the real and imaginary parts are handled separately.
Examples
ceil(2.3) 3 ceil(-2.3) -2 ceil(2.3-4.5j) 3-4j
See also
complex
Make a complex number.
Syntax
z = complex(x, y)
Description
complex(x,y) makes a complex number from its real part x and imaginary part y. The imaginary part of its input arguments is ignored.
Examples
complex(2, 3) 2 + 3j complex(1:5, 2) 1+2j 2+2j 3+2j 4+2j 5+2j
See also
conj
Complex conjugate value.
Syntax
w = conj(z)
Description
conj(z) changes the sign of the imaginary part of the complex number z.
Example
conj([1+2j,-3-5j,4,0]) 1-2j -3+5j 4 0
See also
imag, angle, j, operator -
cos
Cosine.
Syntax
y = cos(x)
Description
cos(x) gives the cosine of x, which is complex if x is complex.
Example
cos([0, 1+2j]) 1 2.0327-3.0519j
See also
cosd cotd cscd secd sind tand
Trigonometric functions with angles in degrees.
Syntax
y = cosd(x) y = cotd(x) y = cscd(x) y = secd(x) y = sind(x) y = tand(x)
Description
Trigonometric functions whose name ends with a d have an argument expressed in degrees instead of radians.
Examples
cosd(20) 0.9397 cos(20 * pi / 180) 0.9397
See also
acosd, acotd, acscd, asecd, asind, atand, atan2d, cos, cot, csc, sec, sin, tan
cosh
Hyperbolic cosine.
Syntax
y = cosh(x)
Description
cos(x) gives the hyperbolic cosine of x, which is complex if x is complex.
Example
cosh([0, 1+2j]) 1 -0.6421+1.0686j
See also
cot
Cotangent.
Syntax
y = cot(x)
Description
cot(x) gives the cotangent of x, which is complex if x is.
See also
coth
Hyperbolic cotangent.
Syntax
y = coth(x)
Description
coth(x) gives the hyperbolic cotangent of x, which is complex if x is.
See also
csc
Cosecant.
Syntax
y = csc(x)
Description
csc(x) gives the cosecant of x, which is complex if x is.
See also
csch
Hyperbolic cosecant.
Syntax
y = csch(x)
Description
csch(x) gives the hyperbolic cosecant of x, which is complex if x is.
See also
diln
Dilogarithm.
Syntax
y = diln(x)
Description
diln(x) gives the dilogarithm, or Spence's integral, of x. Argument and result are real (imaginary part is discarded). The dilogarithm is defined as
Example
diln([0.2, 0.7, 10]) -1.0748 -0.3261 3.9507
double
Conversion to double-precision numbers.
Syntax
B = double(A)
Description
double(A) converts number or array A to double precision. A can be any kind of numeric value (real, complex, or integer), or a character or logical array.
To keep the integer type of logical and character arrays, the unitary operator + should be used instead.
Examples
double(uint8(3)) 3 double('AB') 65 66 islogical(double(1>2)) false
See also
uint8 and related functions, single, cast, operator +, setstr, char, logical
ellipam
Jacobi elliptic amplitude.
Syntax
phi = ellipam(u, m) phi = ellipam(u, m, tol)
Description
ellipam(u,m) gives the Jacobi elliptic amplitude phi.
Parameter m must be in [0,1]. The Jacobi elliptic amplitude is the
inverse of the Jacobi integral of the first kind, such that
ellipam(u,m,tol) uses tolerance tol; the default tolerance is eps.
Example
phi = ellipam(2.7, 0.6) phi = 2.0713 u = ellipf(phi, 0.6) u = 2.7
See also
ellipe
Jacobi elliptic integral of the second kind.
Syntax
u = ellipe(phi, m)
Description
ellipe(phi,m) gives the Jacobi elliptic integral of the second kind, defined as
Complete elliptic integrals of first and second kinds, with phi=pi/2, can be obtained with ellipke.
See also
ellipf
Jacobi elliptic integral of the first kind.
Syntax
u = ellipf(phi, m)
Description
ellipf(phi,m) gives the Jacobi elliptic integral of the first kind, defined as
Complete elliptic integrals of first and second kinds, with phi=pi/2, can be obtained with ellipke.
See also
ellipj
Jacobi elliptic functions.
Syntax
(sn, cn, dn) = ellipj(u, m) (sn, cn, dn) = ellipj(u, m, tol)
Description
ellipj(u,m) gives the Jacobi elliptic function sn, cn, and dn.
Parameter m must be in [0,1]. These functions are based on the
Jacobi elliptic amplitude
ellipj(u,m,tol) uses tolerance tol; the default tolerance is eps.
Examples
(sn, cn, dn) = ellipj(2.7, 0.6) sn = 0.8773 cn = -0.4799 dn = 0.7336 sin(ellipam(2.7, 0.6)) 0.8773 ellipj(0:5, 0.3) 0.0000 0.8188 0.9713 0.4114 -0.5341 -0.9930
See also
ellipke
Complete elliptic integral.
Syntax
(K, E) = ellipke(m) (K, E) = ellipke(m, tol)
Description
(K,E)=ellipke(m) gives the complete elliptic integrals of the first kind K=F(m) and second kind E=E(m), defined as
Parameter m must be in [0,1].
ellipke(m,tol) uses tolerance tol; the default tolerance is eps.
Example
(K, E) = ellipke(0.3) K = 1.7139 E = 1.4454
See also
eps
Difference between 1 and the smallest number x such that x > 1.
Syntax
e = eps e = eps(x) e = eps(type)
Description
Because of the floating-point encoding of "real" numbers, the absolute precision depends on the magnitude of the numbers. The relative precision is characterized by the number given by eps, which is the smallest double positive number such that 1+eps can be distinguished from 1.
eps(x) gives the smallest number e such that x+e has the same sign as x and can be distinguished from x. It takes into account whether x is a double or a single number. If x is an array, the result has the same size; each element corresponds to an element of the input.
eps('single') gives the smallest single positive number e such that 1single+e can be distinguished from 1single. eps('double') gives the same value as eps without input argument.
Examples
eps 2.2204e-16 1 + eps - 1 2.2204e-16 eps / 2 1.1102e-16 1 + eps / 2 - 1 0
See also
erf
Error function.
Syntax
y = erf(x)
Description
erf(x) gives the error function of x. Argument and result are real (imaginary part is discarded). The error function is defined as
Example
erf(1) 0.8427
See also
erfc
Complementary error function.
Syntax
y = erfc(x)
Description
erfc(x) gives the complementary error function of x. Argument and result are real (imaginary part is discarded). The complementary error function is defined as
Example
erfc(1) 0.1573
See also
erfcinv
Inverse complementary error function.
Syntax
x = erfcinv(y)
Description
erfcinv(y) gives the value x such that y=erfc(x). Argument and result are real (imaginary part is discarded). y must be in the range [0,2]; values outside this range give nan.
Example
y = erfc(0.8) y = 0.2579 erfcinv(y) 0.8
See also
erfcx
Scaled complementary error function.
Syntax
y = erfcx(x)
Description
erfcx(x) gives the scaled complementary error function of x, defined as exp(x^2)*erfc(x). Argument and result are real (imaginary part is discarded).
Example
erfcx(1) 0.4276
See also
erfinv
Inverse error function.
Syntax
x = erfinv(y)
Description
erfinv(y) gives the value x such that y=erf(x). Argument and result are real (imaginary part is discarded). y must be in the range [-1,1]; values outside this range give nan.
Example
y = erf(0.8) y = 0.7421 erfinv(y) 0.8
See also
exp
Exponential.
Syntax
y = exp(x)
Description
exp(x) is the exponential of x, i.e. 2.7182818284590446...^x.
Example
exp([0,1,0.5j*pi]) 1 2.7183 1j
See also
log, expm1, expm, operator .^
expm1
Exponential minus one.
Syntax
y = expm1(x)
Description
expm1(x) is exp(x)-1 with improved precision for small x.
Example
expm1(1e-15) 1e-15 exp(1e-15)-1 1.1102e-15
See also
factor
Prime factors.
Syntax
v = factor(n)
Description
factor(n) gives a row vector which contains the prime factors of n in ascending order. Multiple prime factors are repeated.
Example
factor(350) 2 5 5 7
See also
factorial
Factorial.
Syntax
y = factorial(n)
Description
factorial(n) gives the factorial n! of nonnegative integer n. If the input argument is negative or noninteger, the result is NaN. The imaginary part is ignored.
Examples
factorial(5) 120 factorial([-1,0,1,2,3,3.14]) nan 1 1 2 6 nan
See also
fix
Rounding towards 0.
Syntax
y = fix(x)
Description
fix(x) truncates the fractional part of x. If the argument is a complex number, the real and imaginary parts are handled separately.
Examples
fix(2.3) 2 fix(-2.6) -2
See also
flintmax
Largest of the set of consecutive integers stored as floating point.
Syntax
x = flintmax x = flintmax(type)
Description
flintmax gives the largest positive integer number in double precision such that all smaller integers can be represented in double precision.
flintmax(type) gives the largest positive integer number in double precision if type is 'double', or in single precision if type is 'single'. flintmax is 2^53 and flintmax('single') is 2^24.
Examples
flintmax 9007199254740992 flintmax - 1 9007199254740991 flintmax + 1 9007199254740992 flintmax + 2 9007199254740994
See also
floor
Rounding towards -infinity.
Syntax
y = floor(x)
Description
floor(x) gives the largest integer smaller than or equal to x. If the argument is a complex number, the real and imaginary parts are handled separately.
Examples
floor(2.3) 2 floor(-2.3) -3
See also
gamma
Gamma function.
Syntax
y = gamma(x)
Description
gamma(x) gives the gamma function of x. Argument and result are real (imaginary part is discarded). The gamma function is defined as
For positive integer values,
Examples
gamma(5) 24 gamma(-3) inf gamma(-3.5) 0.2701
See also
beta, gammaln, gammainc, factorial
gammainc
Incomplete gamma function.
Syntax
y = gammainc(x,a)
Description
gammainc(x,a) gives the incomplete gamma function of x and a. Arguments and result are real (imaginary part is discarded). x must be nonnegative. The incomplete gamma function is defined as
Example
gammainc(2,1.5) 0.7385
See also
gammaln
Logarithm of gamma function.
Syntax
y = gammaln(x)
Description
gammaln(x) gives the logarithm of the gamma function of x. Argument and result are real (imaginary part is discarded). gammaln does not rely on the computation of the gamma function to avoid overflows for large numbers.
Examples
gammaln(1000) 5905.2204 gamma(1000) inf
See also
gcd
Greatest common divisor.
Syntax
q = gcd(a, b)
Description
gcd(a,b) gives the greatest common divisor of integer numbers a and b.
Example
gcd(72, 56) 8
See also
goldenratio
Golden ratio constant.
Syntax
x = goldenratio
Description
goldenratio is the golden ration
Example
goldenratio 1.6180
See also
hypot
Hypotenuse.
Syntax
c = hypot(a, b)
Description
hypot(a,b) gives the square root of the square of a and b, or of their absolute value if they are complex. The result is always real. hypot avoids overflow when the result itself does not overflow.
Examples
hypot(3, 4) 5 hypot([1,2,3+4j,inf], 5) 5.099 5.3852 5.831 inf
See also
i j
Imaginary unit.
Syntax
i j 1.23e4i 1.23e4j
Description
i or j are the imaginary unit, i.e. the pure imaginary number whose square is -1. i and j are equivalent.
Used as a suffix appended without space to a number, i or j mark an imaginary number. They must follow the fractional part and the exponent, if any; for single-precision numbers, they must precede the single suffix.
To obtain a complex number i, you can write either i or 1i (or j or 1j). The second way is safer, because variables i and j are often used as indices and would hide the meaning of the built-in functions. The expression 1i is always interpreted as an imaginary constant number.
Imaginary numbers are displayed with i or j depending on the option set with the format command.
Examples
i 1j format i 2i 2i 2single + 5jsingle 2+5i (single)
See also
icdf
Inverse cumulative distribution function.
Syntax
x = icdf(distribution,p) x = icdf(distribution,p,a1) x = icdf(distribution,p,a1,a2)
Description
icdf(distribution,p) calculates the value of x such that cdf(distribution,x) is p. The distribution is specified with the first argument, a string; case is ignored ('t' and 'T' are equivalent). Additional arguments must be provided for some distributions. The distributions are given in the table below. Default values for the parameters, when mentioned, mean that the parameter may be omitted.
Distribution | Name | Parameters |
---|---|---|
beta | beta | a and b |
chi2 chisquare |
deg. of freedom |
|
gamma | shape |
|
F | f | deg. of freedom |
lognormal | logn lognormal |
mean (0) and st. dev. (1) |
normal | norm normal |
mean (0) and st. dev. (1) |
Student's T | t student |
deg. of freedom |
uniform | unif uniform |
limits of the range (0 and 1) |
Example
x = icdf('chi2', 0.6, 3) x = 2.9462 cdf('chi2', x, 3) 0.6000
See also
imag
Imaginary part of a complex number.
Syntax
im = imag(z)
Description
imag(z) is the imaginary part of the complex number z, or 0 if z is real.
Examples
imag(1+2j) 2 imag(1) 0
See also
inf
Infinity.
Syntax
x = inf x = Inf x = inf(n) x = inf(n1,n2,...) x = inf([n1,n2,...]) x = inf(..., type)
Description
inf is the number which represents infinity. Most mathematical functions accept infinity as input argument and yield an infinite result if appropriate. Infinity and minus infinity are two different quantities.
With integer non-negative arguments, inf creates arrays whose elements are infinity. Arguments are interpreted the same way as zeros and ones.
The last argument of inf can be a string to specify the type of the result: 'double' for double-precision (default), or 'single' for single-precision.
Examples
1/inf 0 -inf -inf
See also
isfinite, isinf, nan, zeros, ones
iscolumn
Test for a column vector.
Syntax
b = iscolumn(x)
Description
iscolumn(x) is true if the input argument is a column vector (real or complex 2-dimension array of any floating-point or integer type, character or logical value with second dimension equal to 1, or empty array), and false otherwise.
Examples
iscolumn([1, 2, 3]) false iscolumn([1; 2]) true iscolumn(7) true iscolumn([1, 2; 3, 4]) false
See also
isrow, ismatrix, isscalar, isnumeric, size, ndims, length
isfinite
Test for finiteness.
Syntax
b = isfinite(x)
Description
isfinite(x) is true if the input argument is a finite number (neither infinite nor nan), and false otherwise. The result is performed on each element of the input argument, and the result has the same size.
Example
isfinite([0,1,nan,inf]) T T F F
See also
isfloat
Test for a floating-point object.
Syntax
b = isfloat(x)
Description
isfloat(x) is true if the input argument is a floating-point type (double or single), and false otherwise.
Examples
isfloat(2) true isfloat(2int32) false
See also
isinf
Test for infinity.
Syntax
b = isinf(x)
Description
isinf(x) is true if the input argument is infinite (neither finite nor nan), and false otherwise. The result is performed on each element of the input argument, and the result has the same size.
Example
isinf([0,1,nan,inf]) F F F T
See also
isinteger
Test for an integer object.
Syntax
b = isinteger(x)
Description
isinteger(x) is true if the input argument is an integer type (including char and logical), and false otherwise.
Examples
isinteger(2int16) true isinteger(false) true isinteger('abc') true isinteger(3) false
See also
ismatrix
Test for a matrix.
Syntax
b = ismatrix(x)
Description
ismatrix(x) is true if the input argument is a matrix (real or complex 2-dimension array of any floating-point or integer type, character or logical value with, or empty array), and false otherwise.
Examples
ismatrix([1, 2, 3]) true ismatrix([1; 2]) true ismatrix(7) true ismatrix([1, 2; 3, 4]) true ismatrix(ones([2,2,1]) true ismatrix(ones([1,2,2]) false
See also
isrow, iscolumn, isscalar, isnumeric, isscalar, size, ndims, length
isnan
Test for Not a Number.
Syntax
b = isnan(x)
Description
isnan(x) is true if the input argument is nan (not a number), and false otherwise. The result is performed on each element of the input argument, and the result has the same size.
Example
isnan([0,1,nan,inf]) F F T F
See also
isnumeric
Test for a numeric object.
Syntax
b = isnumeric(x)
Description
isnumeric(x) is true if the input argument is numeric (real or complex scalar, vector, or array), and false otherwise.
Examples
isnumeric(pi) true isnumeric('abc') false
See also
ischar, isfloat, isinteger, isscalar
isprime
Prime number test.
Syntax
b = isprime(n)
Description
isprime(n) returns true if n is a prime number, or false otherwise. If n is a matrix, the test is applied to each element and the result is a matrix the same size.
Examples
isprime(7) true isprime([0, 2, 10]) F T F
See also
isrow
Test for a row vector.
Syntax
b = isrow(x)
Description
isrow(x) is true if the input argument is a row vector (real or complex 2-dimension array of any floating-point or integer type, character or logical value with first dimension equal to 1, or empty array), and false otherwise.
Examples
isrow([1, 2, 3]) true isrow([1; 2]) false isrow(7) true isrow([1, 2; 3, 4]) false
See also
iscolumn, ismatrix, isscalar, isnumeric, size, ndims, length
isscalar
Test for a scalar number.
Syntax
b = isscalar(x)
Description
isscalar(x) is true if the input argument is scalar (real or complex number of any floating-point or integer type, character or logical value), and false otherwise.
Examples
isscalar(2) true isscalar([1, 2, 5]) false
See also
isnumeric, isvector, ismatrix, size
isvector
Test for a vector.
Syntax
b = isvector(x)
Description
isvector(x) is true if the input argument is a row or column vector (real or complex 2-dimension array of any floating-point or integer type, character or logical value with one dimension equal to 1, or empty array), and false otherwise.
Examples
isvector([1, 2, 3]) true isvector([1; 2]) true isvector(7) true isvector([1, 2; 3, 4]) false
See also
isnumeric, isscalar, iscolumn, isrow, size, ndims, length
lcm
Least common multiple.
Syntax
q = lcm(a, b)
Description
lcm(a,b) gives the least common multiple of integer numbers a and b.
Example
lcm(72, 56) 504
See also
log
Natural (base e) logarithm.
Syntax
y = log(x)
Description
log(x) gives the natural logarithm of x. It is the inverse of exp. The result is complex if x is not real positive.
Example
log([-1,0,1,10,1+2j]) 0+3.1416j inf 0 2.3026 0.8047+1.1071j
See also
log10, log2, log1p, reallog, exp
log10
Decimal logarithm.
Syntax
y = log10(x)
Description
log10(x) gives the decimal logarithm of x, defined by log10(x) = log(x)/log(10). The result is complex if x is not real positive.
Example
log10([-1,0,1,10,1+2j]) 0+1.3644j inf 0 1 0.3495+0.4808j
See also
log1p
Logarithm of x plus one.
Syntax
y = log1p(x)
Description
log1p(x) is log(1+x) with improved precision for small x.
Example
log1p(1e-15) 1e-15 log(1 + 1e-15) 1.1102e-15
See also
log2
Base 2 logarithm.
Syntax
y = log2(x)
Description
log2(x) gives the base 2 logarithm of x, defined as log2(x)=log(x)/log(2). The result is complex if x is not real positive.
Example
log2([1, 2, 1024, 2000, -5]) 0 1 10 10.9658 2.3219+4.5324j
See also
mod
Modulo.
Syntax
m = mod(x, y)
Description
mod(x,y) gives the modulo of x divided by y, i.e. a number m between 0 and y such that x = q*y+m with integer q. Imaginary parts, if they exist, are ignored.
Examples
mod(10,7) 3 mod(-10,7) 4 mod(10,-7) -4 mod(-10,-7) -3
See also
nan
Not a Number.
Syntax
x = nan x = NaN x = nan(n) x = nan(n1,n2,...) x = nan([n1,n2,...]) x = nan(..., type)
Description
NaN (Not a Number) is the result of the primitive floating-point functions or operators called with invalid arguments. For example, 0/0, inf-inf and 0*inf all result in NaN. When used in an expression, NaN propagates to the result. All comparisons involving NaN result in false, except for comparing NaN with any number for inequality, which results in true.
Contrary to built-in functions usually found in the underlying operating system, many functions which would result in NaNs give complex numbers when called with arguments in a certain range.
With integer non-negative arguments, nan creates arrays whose elements are NaN. Arguments are interpreted the same way as zeros and ones.
The last argument of nan can be a string to specify the type of the result: 'double' for double-precision (default), or 'single' for single-precision.
Examples
nan nan 0*nan nan nan==nan false nan~=nan true log(-1) 0+3.1416j
See also
nchoosek
Binomial coefficient.
Syntax
b = nchoosek(n, k)
Description
nchoosek(n,k) gives the number of combinations of n objects taken k at a time. Both n and k must be nonnegative integers with k<n.
Examples
nchoosek(10,4) 210 nchoosek(10,6) 210
See also
nthroot
Real nth root.
Syntax
y = nthroot(x,n)
Description
nthroot(x,n) gives the real nth root of real number x. If x is positive, it is x.^(1./n); if x is negative, it is -abs(x).^(1./n) if n is an odd integer, or NaN otherwise.
Example
nthroot([-2,2], 3) -1.2599 1.2599 [-2,2] .^ (1/3) 0.6300+1.0911i 1.2599
See also
Probability density function.
Syntax
y = pdf(distribution,x) y = pdf(distribution,x,a1) y = pdf(distribution,x,a1,a2)
Description
pdf(distribution,x) gives the probability of a density function. The distribution is specified with the first argument, a string; case is ignored ('t' and 'T' are equivalent). Additional arguments must be provided for some distributions. See cdf for the list of distributions.
See also
pi
Constant
Syntax
x = pi
Description
pi is the number
Example
exp(1j * pi) -1
See also
goldenratio, i, j, eps
pol2cart
Polar to Cartesian coordinates transform.
Syntax
(x, y) = pol2cart(phi, r) (x, y, z) = pol2cart(phi, r, z)
Description
(x,y)=pol2cart(phi,r) transforms polar coordinates phi
and r to Cartesian coordinates x and y such that
(x,y,z)=pol2cart(phi,r,z) transforms cylindrical coordinates to Cartesian coordinates, leaving z unchanged.
Example
(x, y) = pol2cart(1, 2) x = 1.0806 y = 1.6829
See also
random
Random generator for distribution function.
Syntax
x = random(distribution) x = random(distribution, a1) x = random(distribution, a1, a2) x = random(..., size)
Description
random(distribution,a1,a2) calculates a pseudo-random number whose distribution function is specified by name distribution and parameters a1 and a2 (some distributions have a single parameter). The distributions are given in the table below. Unlike in functions pdf, cdf and icdf, parameters do not have default values and must be specified.
Additional input arguments specify the size of the result, either as a vector (or a single scalar for a square matrix) or as scalar values. The result is an array of the specified size where each value is an independent pseudo-random variable. The default size is 1 (scalar).
If the parameters are arrays, the result is an array of the same size and each element is an independent pseudo-random variable whose distribution has its parameters at the corresponding position. The size, if specified, must be the same.
Distribution | Name | Parameters |
---|---|---|
beta | beta | a and b |
Cauchy | cauchy | a and b |
chi | deg. of freedom |
|
chi2 chisquare |
deg. of freedom |
|
gamma | shape |
|
exponential | exp exponential |
mean |
F | f | deg. of freedom |
half-normal | half-normal | |
Laplace | laplace | mean and scale |
lognormal | logn lognormal |
mean and st. dev. |
Nakagami | nakagami | |
normal | norm normal |
mean and st. dev. |
Rayleigh | rayl rayleigh |
b |
Student's T | t student |
deg. of freedom |
uniform | unif uniform |
limits of the range |
Weibull | weib weibull |
shape a and scale b |
Example
Array of 5 pseudo-random numbers whose distribution is
random('chi2', 3, [1, 5]) 1.6442 0.4164 2.0272 2.7962 4.5896
See also
pdf, cdf, icdf, rand, randn, rng
rat
Rational approximation.
Syntax
(num, den) = rat(x) (num, den) = rat(x, tol) (num, den) = rat(x, tol=tol)
Description
rat(x,tol) returns the numerator and the denominator of a rational approximation of real number x with the smallest integer numerator and denominator which fulfil absolute tolerance tol. If the input argument x is an array, output arguments are arrays of the same size. Negative numbers give a negative numerator. The tolerance can be passed as a named argument.
With one input argument, rat(x) uses tolerance tol=1e-6*norm(x,1). With one output argument, rat(x) gives the rational approximation itself as a floating-point number.
With command format rat, all numeric results as displayed as rational aproximations with the default tolerance, including complex numbers.
Example
(num,den) = rat(pi) num = 355 den = 113 num/den 3.141592920353982
See also
real
Real part of a complex number.
Syntax
re = real(z)
Description
real(z) is the real part of the complex number z, or z if z is real.
Examples
real(1+2j) 1 real(1) 1
See also
reallog
Real natural (base e) logarithm.
Syntax
y = reallog(x)
Description
reallog(x) gives the real natural logarithm of x. It is the inverse of exp for real numbers. The imaginary part of x is ignored. The result is NaN if x is negative.
Example
reallog([-1,0,1,10,1+2j]) nan inf 0 2.3026 0
See also
realmax realmin
Largest and smallest real numbers.
Syntax
x = realmax x = realmax(n) x = realmax(n1,n2,...) x = realmax([n1,n2,...]) x = realmax(..., type) x = realmin x = realmin(...)
Description
realmax gives the largest positive real number in double precision. realmin gives the smallest positive real number in double precision which can be represented in normalized form (i.e. with full mantissa precision).
With integer non-negative arguments, realmax and realmin create arrays whose elements are all set to the respective value. Arguments are interpreted the same way as zeros and ones.
The last argument of realmax and realmin can be a string to specify the type of the result: 'double' for double-precision (default), or 'single' for single-precision.
Examples
realmin 2.2251e-308 realmin('single') 1.1755e-38 realmax 1.7977e308 realmax('single') 3.4028e38single realmax + eps(realmax) inf
See also
inf, ones, zeros, eps, flintmax
realpow
Real power.
Syntax
z = realpow(x, y)
Description
realpow(x,y) gives the real value of x to the power y. The imaginary parts of x and y are ignored. The result is NaN if it is not defined for the input arguments. If the arguments are arrays, their size must match or one of them must be a scalar number; the power is performed element-wise.
See also
operator .^, reallog, realsqrt
realsqrt
Real square root.
Syntax
y = realsqrt(x)
Description
realsqrt(x) gives the real square root of x. The imaginary part of x is ignored. The result is NaN if x is negative.
Example
realsqrt([-1,0,1,10,1+2j]) nan 0 1 3.1623 1
See also
sqrt, reallog, realpow, nthroot
rem
Remainder of a real division.
Syntax
r = rem(x, y)
Description
rem(x,y) gives the remainder of x divided by y, i.e. a number r between 0 and sign(x)*abs(y) such that x = q*y+r with integer q. Imaginary parts, if they exist, are ignored.
Examples
rem(10,7) 3 rem(-10,7) -3 rem(10,-7) 3 rem(-10,-7) -3
See also
round
Rounding to the nearest integer.
Syntax
y = round(x)
Description
round(x) gives the integer nearest to x. If the argument is a complex number, the real and imaginary parts are handled separately.
Examples
round(2.3) 2 round(2.6) 3 round(-2.3) -2
See also
roundn
Rounding to a specified precision.
Syntax
y = roundn(x, n)
Description
roundn(x,n) rounds x to the nearest multiple of 10^n. If argument x is a complex number, the real and imaginary parts are handled separately. roundn(x,0) gives the same result as round(x).
Argument n must be a real integer. If x and/or n are arrays, rounding is performed separately on each element.
Examples
roundn(pi, -2) 3.1400 roundn(1000 * pi, 1) 3140 roundn(pi, [-3, -1]) 3.1420 3.1000
See also
sign
Sign of a real number or direction of a complex number.
Syntax
s = sign(x) z2 = sign(z1)
Description
With a real argument, sign(x) is 1 if x>0, 0 if x==0, or -1 if x<0. With a complex argument, sign(z1) is a complex value with the same phase as z1 and whose magnitude is 1.
Examples
sign(-2) -1 sign(1+1j) 0.7071+0.7071j sign([0, 5]) 0 1
See also
sec
Secant.
Syntax
y = sec(x)
Description
sec(x) gives the secant of x, which is complex if x is.
See also
sech
Hyperbolic secant.
Syntax
y = sech(x)
Description
acot(x) gives the hyperbolic secant of x, which is complex if x is.
See also
sin
Sine.
Syntax
y = sin(x)
Description
sin(x) gives the sine of x, which is complex if x is complex.
Example
sin(2) 0.9093
See also
sinc
Sinc.
Syntax
y = sinc(x)
Description
sinc(x) gives the sinc of x, i.e. sin(pi*x)/(pi*x) if x~=0 or 1 if x==0. The result is complex if x is complex.
Example
sinc(1.5) -0.2122
See also
single
Conversion to single-precision numbers.
Syntax
B = single(A)
Description
single(A) converts number or array A to single precision. A can be any kind of numeric value (real, complex, or integer), or a character or logical array.
Single literal numbers can be entered as a floating-point number with the single suffix.
Examples
single(pi) 3.1416single single('AB') 1x2 single array 65 66 3.7e4single 37000single
See also
double, uint8 and related functions, operator +, setstr, char, logical
sinh
Hyperbolic sine.
Syntax
y = sinh(x)
Description
sinh(x) gives the hyperbolic sine of x, which is complex if x is complex.
Example
sinh(2) 3.6269
See also
sph2cart
Spherical to Cartesian coordinates transform.
Syntax
(x, y, z) = sph2cart(phi, theta, r)
Description
(x,y,z)=sph2cart(phi,theta,r) transforms polar coordinates phi,
theta, and r to Cartesian coordinates x,
y, and z such that
Example
(x, y, z) = sph2cart(1, 2, 3) x = -0.6745 y = -1.0505 z = 2.7279
See also
sqrt
Square root.
Syntax
r = sqrt(z)
Description
sqrt(z) gives the square root of z, which is complex if z is not real positive.
Examples
sqrt(4) 2 sqrt([1 4 -9 3+4j]) 1 2 3j 2+1j
See also
swapbytes
Conversion between big-endian and little-endian representation.
Syntax
Y = swapbytes(X)
Description
swapbytes(X) swaps the bytes representing number X. If X is an array, each number is swapped separately. The imaginary part, if any, is discarded. X can be of any numeric type. swapbytes is its own inverse for real numbers.
Example
swapbytes(1uint32) 16777216uint32
See also
tan
Tangent.
Syntax
y = tan(x)
Description
tan(x) gives the tangent of x, which is complex if x is complex.
Example
tan(2) -2.185
See also
tanh
Hyperbolic tangent.
Syntax
y = tanh(x)
Description
tanh(x) gives the hyperbolic tangent of x, which is complex if x is complex.
Example
tanh(2) 0.964
See also
typecast
Type conversion with same binary representation.
Syntax
Y = typecast(X, type)
Description
typecast(X,type) changes the numeric array X to the type given by string type, which can be 'double', 'single', 'int8' or any other signed or unsigned integer type, 'char', or 'logical'. The binary representation in memory is preserved. The imaginary part, if any, is discarded. Depending on the conversion, the number of elements is changed, so that the array size in bytes in preserved. The result is a row vector if X is a scalar or a row vector, or a column vector otherwise. The result depends on the computer architecture.
Example
typecast(1uint32, 'uint8') 1x4 uint8 array 0 0 0 1 typecast(pi, 'uint8') 1x8 uint8 array 64 9 33 251 84 68 45 24