Mathematics Functions

abs

Absolute value.

Syntax

x = abs(z)

Description

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.

Example

abs([2,-3,0,3+4j]
  [2,3,0,5]

See also

angle, real, imag

acos

Arccosine.

Syntax

y = acos(x)

Description

acos(x) gives the arccosine 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

cos, asin, acosh

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

cosh, asinh, acos

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

abs, atan2

asin

Arc sine.

Syntax

y = asin(x)

Description

asin(x) gives the arcsine 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

sin, acos, asinh

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

sinh, acosh, asin

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

asin, acos, atan2, atanh

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

atan, angle

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

asinh, acosh, atan

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

beta(z,w) = integral from 0 to 1 of t^(z-1) (1-t)^(w-1) dt

Example

beta(1,2)
  0.5

See also

gamma, betaln, betainc

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

betainc(x,z,w) = (1/beta(z,w)) integral from 0 to x of t^(z-1) (1-t)^(w-1) dt

Example

betainc(0.2,1,2)
  0.36

See also

beta, betaln, gammainc

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

beta, betainc, gammaln

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 -infinity to x. 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. The distributions are given in the table below. Default values for the parameters, when mentioned, mean that the parameter may be omitted.

DistributionNameParameters
Cauchy cauchy a and b
chi chi deg. of freedom nu
chi-square chi2
chisquare
deg. of freedom nu
gamma gamma shape alpha and scale lambda
exponential exp
exponential
mean
F f deg. of freedom nu1 and nu2
half-normal half-normal theta
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 nu
uniform unif
uniform
limits of the range (0 and 1)
Weibull weib
weibull
a and b

See also

pdf, erf

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

floor, fix, round

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

sin, acos, cosh

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

sinh, acosh, cos

double

Conversion to double-precision numbers.

Syntax

y = double(x)

Description

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 ===.

Examples

double('A')
  65
islogical(double(1>2))
  0

See also

setstr, char, logical

eps

Difference between 1 and the smallest number x such that x > 1.

Syntax

x = eps

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 positive number such that 1+eps can be distinguished from 1.

Examples

1 + eps / 1.1 - 1
  0
1 + eps - 1
  2.2204e-16

See also

inf, pi, i, j

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

erf(x) = (2/sqrt(pi)) integral from 0 to x of exp(-t^2) dt

Example

erf(1)
  0.8427

See also

erfc

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 error function is defined as

erfc(x) = 1-erf(x) = (2/sqrt(pi)) integral from x to inf of exp(-t^2) dt

Example

erfc(1,2)
  0.1573

See also

erf

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, expm, operator .^

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

floor, ceil, round

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

ceil, fix, round

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

gamma(x) = integral from 0 to infinity of t^(x-1) exp(-t) dt

For positive integer values, gamma(n)=(n-1)!.

Examples

gamma(5)
  24
gamma(-3)
  inf
gamma(-3.5)
  0.2701

See also

beta, gammaln, gammainc

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

gammainc(x,a) = (1/gamma(a)) integral from 0 to x of t^(a-1) exp(-t) dt

Example

gammainc(2,1.5)
  0.7385

See also

gamma, gammaln, betainc

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

gamma, gammainc, betaln

i

Imaginary unit.

Syntax

i
(some real number)i

Description

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.

Examples

i
  1j
2i
  2j

See also

j, imag

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

real, i, j

inf

Infinity.

Syntax

inf
Inf

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.

Example

1/inf
  0
-inf
  -inf

See also

isfinite, isinf

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])
  1 1 0 0

See also

isinf, isnan

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])
  0 0 0 1

See also

isfinite, isnan, inf

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])
  [0,0,1,0]

See also

isinf, nan

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 matrix), and false otherwise.

Examples

isnumeric(pi)
  1
isnumeric('abc')
  0

See also

ischar

j

Imaginary unit.

Syntax

j
(some real number)j

Description

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.

Examples

j
  1j
2j
  2j

See also

i, imag

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, 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

log

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

rem

nan

Not a Number.

Syntax

nan
NaN

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 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.

Examples

nan
  nan
0*nan
  nan
nan==nan
  0
nan~=nan
  1
log(-1)
  0+3.1416j

See also

inf, isnan

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

gamma

pdf

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 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.

See also

cdf

pi

Constant pi.

Syntax

x = pi

Description

pi is the number pi, up to the precision of its floating-point representation.

Example

exp(1j * pi)
  -1

See also

i, j, eps

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

imag

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

mod

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

floor, ceil, fix

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 5

See also

abs

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

cos, asin, sinh

sinc

Sinc.

Syntax

y = sinc(x)

Description

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.

Example

sinc(2)
  0.4546

See also

sin, sinh

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

cosh, asinh, sin

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

chol

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

atan, tanh

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

atanh, tan


Copyright 1998-2001, Calerga.

All rights reserved.