Octave Programming Tutorial/General mathematical functions
From Wikibooks, open books for an open world
Contents
General Mathematical Functions[edit]
Constants[edit]
e
is the base of the natural logarithm.

e
without arguments returns the scalar e.e(N)
returns a square matrix of e of sizeN
.e(N, M, ...)
where the arguments are dimensions of some matrix of e.e(..., CLASS)
whereCLASS
is an optional argument that specifies the return type,double
orsingle
.
eps
is the machine precision and returns the relative spacing between any floating point number and the next representable number. This value is system dependent.

eps
returns the value ofeps(1.0)
.eps(X)
returns the spacing between X and the next value.eps
with more than one argument is treated likee
with the matrix value beingeps(1.0)
.
 All of the constant functions listed are defined exactly like
e

pi
is the ratio of the circumference to the diameter of any circle.I
is the imaginary unit defined soI^2 = 1
.Inf
is used for values that overflow the standard IEEE floating point range or the result of division by zero.NaN
is used for various results that are not well defined or undefined. Note thatNaN
never equals otherNaN
values. Use the functionisnan
to check forNaN
.realmax
is the largest floating point value representable.realmin
is the smallest floating point value representable.
Arithmetic Functions[edit]
floor(X)
andceil(X)
return the highest integer not greater thanX
or lowest integer not less thanX
, respectively.round(X)
andfix(X)
return the integer closest toX
or truncateX
towards zero, respectively.rem(X,Y)
andmod(X,Y)
returns x  y * fix( x ./ y ) or x  y * floor( x ./ y ), they are the same except when dealing with negative arguments.hypot(X, Y)
returns the length of the hypotenuse of a rightangle triangle with the adjacent and opposite of sizeX
andY
.abs(X)
return absolute of x.sign(X)
return sign of the x (1, 0 or +1).
Ordinary Trigonometry[edit]
cos(X)
,sin(x)
andtan(X)
— the elemental functions that we all know and love. They take their arguments in radians.acos(X)
,asin(X)
are the inverses ofcos
andsin
and are able to compute arguments not contained in the range [1,1].atan(X)
andatan2(Y, X)
are the 2 available inverses of tan.atan
is a simple inverse whereasatan2
takes 2 arguments and returns an angle in the appropriate quadrant. More information onatan2
can be found here. Note that one can add the character d to any of the functions except
atan2
and they will work in degrees rather than radians. For example:asind(0.3) = asin(0.3*180/pi)
exp(x)
, exponential funtion of xlog(x)
, natural logarithmic of x, log_{e} NOT log _{10}
Hyperbolic Trigonometry[edit]
cosh(X)
,sinh(X)
andtanh(X)
are analog to their more prosaic counterparts but deal with the unit hyperbola instead of the unit circle. They also take their arguments in radians.acosh(X)
,asinh(X)
andatanh(X)
are the inverses ofcosh
,sinh
andtanh
. Unlike their circular uncles they cannot be made to take their arguments in degrees.