Previous Up Next

8.3.2  Standard functions

The max command finds the maximum of a sequence of real numbers.

Example

max(0,1,2,-1,-2)
     
2           

The min command finds the minimum of a sequence of real numbers.

Example

min(0,1,2,-1,-2)
     
−2           

The abs command finds the absolute value of a real or complex number.

Examples

abs(-5)
     
5           
abs(3+4*i)
     
5           

The sign command finds the sign of a real number (+1 if it is positive, 0 if it is zero, and -1 if it is negative).

Examples

sign(-4)
     
−1           
sign(0)
     
0           

The floor or iPart) command finds the floor of a real number; namely, the largest integer less than or equal to the number.

Examples

floor(4.1)
     
4           
floor(-4.1)
     
−5           

The round command rounds a number to the nearest integer, rounding up in the case of a half-integer.

Examples

round(3.4)
     
3           
round(-3.4)
     
−3           
round(3.5)
     
4           

The ceil or ceiling command finds the ceiling of a real number; namely, the smallest integer greater than or equal to the number.

Examples

ceiling(4.1)
     
5           
ceiling(-4.1)
     
−4           

The frac or fPart command finds the fractional part of a number; informally, the part of the number to the right of the decimal point with the appropriate plus or minus sign. For a positive real number x, the fractional part is x minus the floor of x; for a negative real number x, the fractional part is x minus the ceiling of x.

Examples

frac(3.24)
     
0.24           
frac(-3.24)
     
−0.24           

The trunc command truncates a real number; namely, it removes the fractional part. The truncated number added to the fractional part will equal the original number.

Examples

trunc(3.24)
     
3           
trunc(-3.24)
     
−3           

The id command is the identity function.

Example

id(a,1,"abc",[1,2,3])
     
a,1,“abc”,
1,2,3
          

The sq command squares its argument.

Examples

sq(5)
     
25           
sq(x+y)
     

x+y
2
          
sq([[1,2],[3,4]])
     


    710
    1522


          

(This is a matrix product; see Section 14.2).

sq([1,2,3])
     
14           

(This is the dot product of [1,2,3] with itself.)

The sqrt command finds the square root of its argument.

Examples

sqrt(9)
     
3           
sqrt((x+y)^2)
     

x+y
          
simplify(sqrt([[2,3],[3,5]]))
     


    11
    12


          

The surd command finds roots of quantities.

Example

surd(15.625,3)
     
2.5           

The exp command computes the exponential function.

Example

exp(1.0)
     
2.71828182846           

The log or ln command computes the natural logarithm.

Example

log(2.0)
     
0.69314718056           

The log10 command computes the common logarithm.

Example

log10(1000)
     
3           

The log2 command computes the binary logarithm.

Example

log2(1024)
     
10           

The logb computes the logarithm to a specified base.

Example

logb(10.0,2)
     
3.32192809489           
Trigonometric functions.

Examples

Input with angle_radian equal to 1:

sin(pi/4)
     
2
2
          

Input with angle_radian equal to 0:

sin(30)
     
1
2
          

cos(x) returns the cosine of x. For example, input with angle_radian equal to 1:

cos(pi/6)
     
3
2
          

Input with angle_radian equal to 0:

cos(90)
     
0           

tan(x) returns the tangent of x. For example, input with angle_radian equal to 1:

tan(pi/4)
     
1           

Input with angle_radian equal to 0:

tan(60)
     
3
          

cot(x) returns the cotangent of x. For example, input with angle_radian equal to 1:

cot(pi/6)
     
2
3
2
          

Input with angle_radian equal to 0:

cot(45)
     
1           

sec(x) returns the secant of x. For example, input with angle_radian equal to 1:

sec(pi/3)
     
2           

Input with angle_radian equal to 0:

sec(30)
     
2
3
          

csc(x) returns the cosecant of x. For example, input with angle_radian equal to 1:

csc(pi/4)
     
2
2
          

Input with angle_radian equal to 0:

csc(30)
     
2           
Inverse trigonometric functions.

The asin, acos, atan, acot, asec, acsc commands are the inverse trigonometric functions. The latter are defined by:

arcsin, arccos and arctan are synonyms for asin, acos and atan, respectively.

Examples

Input with angle_radian equal to 1:

asin(1/2)
     
π
6
          

Input with angle_radian equal to 0:

asin(1)
     
π
2
          

acos(x) returns the arccosine of x. For example: Input with angle_radian equal to 1:

acos(sqrt(3)/2)
     
1
6
π
          

Input with angle_radian equal to 0:

acos(-1/2)
     
120           

atan(x) returns the arctangent of x. For example, input with angle_radian equal to 1:

atan(sqrt(3))
     
π
3
          

Input with angle_radian equal to 1:

atan(1)
     
45           

acot(x) returns the arccotangent of x. For example, input with angle_radian equal to 1:

acot(sqrt(3))
     
π
6
          

Input with angle_radian equal to 0:

acot(1/sqrt(3))
     
60           

asec(x) returns the arcsecant of x. For example, input with angle_radian equal to 1:

asec(1)
     
0           

Input with angle_radian equal to 0:

asec(sqrt(2))
     
45           

acsc(x) returns the arccosecant of x. For example, input with angle_radian equal to 1:

acsc(1)
     
π
2
          

Input with angle_radian equal to 0:

acsc(2)
     
30           
Hyperbolic functions.

The sinh, cosh, and tanh commands compute the hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions.

Examples

sinh(1.0)
     
1.17520119364           

cosh(x) returns the hyperbolic cosine of x. For example:

cosh(0)
     
1           

tanh(x) returns the hyperbolic tangent of x. For example:

tanh(-1.0)
     
−0.761594155956           
Inverse hyperbolic functions.

The asinh, acosh, and atanh commands compute the inverse hyperbolic functions.

arcsinh, arccosh and arctanh are synonyms for asinh, acosh and atanh, respectively.

Examples

asinh(2)
     
ln

2+
5


          

acosh(x) returns the inverse hyperbolic cosine of x. For example:

acosh(1)
     
0           

atanh(x) returns the inverse hyperbolic tangent of x. For example:

atanh(1/2)
     
ln
3
2
          

Previous Up Next