Absolute value.
x = abs(z)
abs takes the absolute value of each element of its argument. The result is a matrix of the same size as the argument; each element is non-negative.
abs([2,-3,0,3+4j] [2,3,0,5]
Arccosine.
y = acos(x)
acos(x) gives the arccosine of x, which is complex if x is complex or if abs(x)>1.
acos(2) 0+1.3170j acos([0,1+2j]) 1.5708 1.1437-1.5286j
Inverse hyperbolic cosine.
y = acosh(x)
acosh(x) gives the inverse hyperbolic cosine of x, which is complex if x is complex or if x<1.
acosh(2) 1.3170 acosh([0,1+2j]) 0+1.5708j 1.5286+1.1437j
Phase angle of a complex number.
phi = angle(z)
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.
angle(1+3j) 1.2490 angle([0,1,-1]) 0 0 3.1416
Arc sine.
y = asin(x)
asin(x) gives the arcsine of x, which is complex if x is complex or if abs(x)>1.
asin(0.5) 0.5236 asin(2) 1.5708-1.317j
Inverse hyperbolic sine.
y = asinh(x)
asinh(x) gives the inverse hyperbolic sine of x, which is complex if x is complex.
asinh(2) 1.4436 asinh([0,1+2j]) 0 1.8055+1.7359j
Arc tangent.
y = atan(x)
atan(x) gives the arc tangent of x, which is complex if x is complex.
atan(1) 0.7854
Direction of a point given by its cartesian coordinates.
phi = atan2(y,x)
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.
atan2(1, 1) 0.7854 atan2(-1, -1) -2.3562 atan2(0, 0) 0
Inverse hyperbolic tangent.
y = atanh(x)
atan(x) gives the inverse hyperbolic tangent of x, which is complex if x is complex or if abs(x)>1.
atanh(0.5) 0.5493 atanh(2) 0.5493 + 1.5708j
Beta function.
y = beta(z,w)
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
beta(1,2) 0.5
Incomplete beta function.
y = betainc(x,z,w)
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
betainc(0.2,1,2) 0.36
Logarithm of beta function.
y = betaln(z,w)
betaln(z,w) gives the logarithm of the beta function of z and w. Arguments and result are real (imaginary part is discarded).
betaln(0.5,2) 0.2877
Cumulative distribution function.
y = cdf(distribution,x) y = cdf(distribution,x,a1) y = cdf(distribution,x,a1,a2)
cdf(distribution,x) calculates the integral of a probability density function from
Distribution | Name | Parameters |
---|---|---|
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) |
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 |
a and b |
Rounding towards +infinity.
y = ceil(x)
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.
ceil(2.3) 3 ceil(-2.3) -2 ceil(2.3-4.5j) 3-4j
Complex conjugate value.
w = conj(z)
conj(z) changes the sign of the imaginary part of the complex number z.
conj([1+2j,-3-5j,4,0]) 1-2j -3+5j 4 0
imag, angle, j, operator -
Cosine.
y = cos(x)
cos(x) gives the cosine of x, which is complex if x is complex.
cos([0, 1+2j]) 1 2.0327-3.0519j
Hyperbolic cosine.
y = cosh(x)
cos(x) gives the hyperbolic cosine of x, which is complex if x is complex.
cosh([0, 1+2j]) 1 -0.6421+1.0686j
Conversion to double-precision numbers.
y = double(x)
double(x) resets the logical and string flags associated to x. The logical flag has an effect only when x is used to access the elements of a variable, and in the argument of islogical or ===.
double('A') 65 islogical(double(1>2)) 0
Difference between 1 and the smallest number x such that x > 1.
x = eps
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 positive number such that 1+eps can be distinguished from 1.
1 + eps / 1.1 - 1 0 1 + eps - 1 2.2204e-16
Error function.
y = erf(x)
erf(x) gives the error function of x. Argument and result are real (imaginary part is discarded). The error function is defined as
erf(1) 0.8427
Complementary error function.
y = erfc(x)
erfc(x) gives the complementary error function of x. Argument and result are real (imaginary part is discarded). The error function is defined as
erfc(1,2) 0.1573
Exponential.
y = exp(x)
exp(x) is the exponential of x, i.e. 2.7182818284590446...^x.
exp([0,1,0.5j*pi]) 1 2.7183 1j
Rounding towards 0.
y = fix(x)
fix(x) truncates the fractional part of x. If the argument is a complex number, the real and imaginary parts are handled separately.
fix(2.3) 2 fix(-2.6) -2
Rounding towards -infinity.
y = floor(x)
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.
floor(2.3) 2 floor(-2.3) -3
Gamma function.
y = gamma(x)
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, gamma(n)=(n-1)!.
gamma(5) 24 gamma(-3) inf gamma(-3.5) 0.2701
Incomplete gamma function.
y = gammainc(x,a)
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
gammainc(2,1.5) 0.7385
Logarithm of gamma function.
y = gammaln(x)
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.
gammaln(1000) 5905.2204 gamma(1000) inf
Imaginary unit.
i (some real number)i
i is the imaginary unit, i.e. the pure imaginary number whose square is -1.
To obtain a complex number i, you can write either i or 1i. The second way is safer, because a variable i is often used as an index, and would hide the meaning of the built-in function. The expression 1i is always interpreted as an imaginary constant number.
i 1j 2i 2j
Imaginary part of a complex number.
im = imag(z)
imag(z) is the imaginary part of the complex number z, or 0 if z is real.
imag(1+2j) 2 imag(1) 0
Infinity.
inf Inf
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.
1/inf 0 -inf -inf
Test for finiteness.
b = isfinite(x)
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.
isfinite([0,1,nan,inf]) 1 1 0 0
Test for infinity.
b = isinf(x)
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.
isinf([0,1,nan,inf]) 0 0 0 1
Test for Not a Number.
b = isnan(x)
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.
isnan([0,1,nan,inf]) [0,0,1,0]
Test for a numeric object.
b = isnumeric(x)
isnumeric(x) is true if the input argument is numeric (real or complex scalar, vector, or matrix), and false otherwise.
isnumeric(pi) 1 isnumeric('abc') 0
Imaginary unit.
j (some real number)j
j is the imaginary unit, i.e. the pure imaginary number whose square is -1.
To obtain a complex number j, you can write either j or 1j. The second way is safer, because a variable j is often used as an index, and would hide the meaning of the built-in function. The expression 1j is always interpreted as an imaginary constant number.
j 1j 2j 2j
Natural (base e) logarithm.
y = log(x)
log(x) gives the natural logarithm of x. It is the inverse of exp. The result is complex if x is not real positive.
log([-1,0,1,10,1+2j]) 0+3.1416j inf 0 2.3026 0.8047+1.1071j
Decimal logarithm.
y = log10(x)
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.
log10([-1,0,1,10,1+2j]) 0+1.3644j inf 0 1 0.3495+0.4808j
Modulo.
m = mod(x, y)
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.
mod(10,7) 3 mod(-10,7) 4 mod(10,-7) -4 mod(-10,-7) -3
Not a Number.
nan NaN
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 0 (false), except for comparing NaN with any number for inequality, which results in 1 (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.
nan nan 0*nan nan nan==nan 0 nan~=nan 1 log(-1) 0+3.1416j
Binomial coefficient.
b = nchoosek(n, k)
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.
nchoosek(10,4) 210 nchoosek(10,6) 210
Probability density function.
y = pdf(distribution,x) y = pdf(distribution,x,a1) y = pdf(distribution,x,a1,a2)
pdf(distribution,x) gives the probability of a density function. The distribution is specified with a 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.
Constant
x = pi
pi is the number
exp(1j * pi) -1
Real part of a complex number.
re = real(z)
real(z) is the real part of the complex number z, or z if z is real.
real(1+2j) 1 real(1) 1
Remainder of a real division.
r = rem(x, y)
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.
rem(10,7) 3 rem(-10,7) -3 rem(10,-7) 3 rem(-10,-7) -3
Rounding to the nearest integer.
y = round(x)
round(x) gives the integer nearest to x. If the argument is a complex number, the real and imaginary parts are handled separately.
round(2.3) 2 round(2.6) 3 round(-2.3) -2
Sign of a real number or direction of a complex number.
s = sign(x) z2 = sign(z1)
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.
sign(-2) -1 sign(1+1j) 0.7071+0.7071j sign([0, 5]) 0 5
Sine.
y = sin(x)
sin(x) gives the sine of x, which is complex if x is complex.
sin(2) 0.9093
Sinc.
y = sinc(x)
sinc(x) gives the sinc of x, i.e. sin(x)/x if x~=0 or 1 if x==0. The result is complex if x is complex.
sinc(2) 0.4546
Hyperbolic sine.
y = sinh(x)
sinh(x) gives the hyperbolic sine of x, which is complex if x is complex.
sinh(2) 3.6269
Square root.
r = sqrt(z)
sqrt(z) gives the square root of z, which is complex if z is not real positive.
sqrt(4) 2 sqrt([1 4 -9 3+4j]) 1 2 3j 2+1j
Tangent.
y = tan(x)
tan(x) gives the tangent of x, which is complex if x is complex.
tan(2) -2.185
Hyperbolic tangent.
y = tanh(x)
tanh(x) gives the hyperbolic tangent of x, which is complex if x is complex.
tanh(2) 0.964