Next: Functions for Complex Numbers, Previous: Mathematical Functions, Up: Mathematical Functions [Contents][Index]
The abs
function represents the mathematical absolute value function and
works for both numerical and symbolic values. If the argument, z, is a
real or complex number, abs
returns the absolute value of z. If
possible, symbolic expressions using the absolute value function are
also simplified.
Maxima can differentiate, integrate and calculate limits for expressions
containing abs
. The abs_integrate
package further extends
Maxima’s ability to calculate integrals involving the abs function. See
(%i12) in the examples below.
When applied to a list or matrix, abs
automatically distributes over
the terms. Similarly, it distributes over both sides of an
equation. To alter this behaviour, see the variable distribute_over
.
See also cabs
.
Examples:
Calculation of abs
for real and complex numbers, including numerical
constants and various infinities. The first example shows how abs
distributes over the elements of a list.
(%i1) abs([-4, 0, 1, 1+%i]); (%o1) [4, 0, 1, sqrt(2)] (%i2) abs((1+%i)*(1-%i)); (%o2) 2 (%i3) abs(%e+%i); 2 (%o3) sqrt(%e + 1) (%i4) abs([inf, infinity, minf]); (%o4) [inf, inf, inf]
Simplification of expressions containing abs
:
(%i5) abs(x^2); 2 (%o5) x (%i6) abs(x^3); 2 (%o6) x abs(x) (%i7) abs(abs(x)); (%o7) abs(x) (%i8) abs(conjugate(x)); (%o8) abs(x)
Integrating and differentiating with the abs
function. Note that more
integrals involving the abs
function can be performed, if the
abs_integrate
package is loaded. The last example shows the Laplace
transform of abs
: see laplace
.
(%i9) diff(x*abs(x),x),expand; (%o9) 2 abs(x) (%i10) integrate(abs(x),x); x abs(x) (%o10) -------- 2 (%i11) integrate(x*abs(x),x); / [ (%o11) I x abs(x) dx ] / (%i12) load("abs_integrate")$ (%i13) integrate(x*abs(x),x); 2 3 x abs(x) x signum(x) (%o13) --------- - ------------ 2 6 (%i14) integrate(abs(x),x,-2,%pi); 2 %pi (%o14) ---- + 2 2 (%i15) laplace(abs(x),x,s); 1 (%o15) -- 2 s
‘Category: Mathematical functions’
When x is a real number, return the least integer that is greater than or equal to x.
If x is a constant expression (10 * %pi
, for example),
ceiling
evaluates x using big floating point numbers, and
applies ceiling
to the resulting big float. Because ceiling
uses
floating point evaluation, it’s possible, although unlikely, that ceiling
could return an erroneous value for constant inputs. To guard against errors,
the floating point evaluation is done using three values for fpprec
.
For non-constant inputs, ceiling
tries to return a simplified value.
Here are examples of the simplifications that ceiling
knows about:
(%i1) ceiling (ceiling (x)); (%o1) ceiling(x)
(%i2) ceiling (floor (x)); (%o2) floor(x)
(%i3) declare (n, integer)$
(%i4) [ceiling (n), ceiling (abs (n)), ceiling (max (n, 6))]; (%o4) [n, abs(n), max(6, n)]
(%i5) assume (x > 0, x < 1)$
(%i6) ceiling (x); (%o6) 1
(%i7) tex (ceiling (a)); $$\left \lceil a \right \rceil$$ (%o7) false
The ceiling
function distributes over lists, matrices and equations.
See distribute_over
.
Finally, for all inputs that are manifestly complex, ceiling
returns
a noun form.
If the range of a function is a subset of the integers, it can be declared to
be integervalued
. Both the ceiling
and floor
functions
can use this information; for example:
(%i1) declare (f, integervalued)$
(%i2) floor (f(x)); (%o2) f(x)
(%i3) ceiling (f(x) - 1); (%o3) f(x) - 1
Example use:
(%i1) unitfrac(r) := block([uf : [], q], if not(ratnump(r)) then error("unitfrac: argument must be a rational number"), while r # 0 do ( uf : cons(q : 1/ceiling(1/r), uf), r : r - q), reverse(uf)); (%o1) unitfrac(r) := block([uf : [], q], if not ratnump(r) then error("unitfrac: argument must be a rational number"), 1 while r # 0 do (uf : cons(q : ----------, uf), r : r - q), 1 ceiling(-) r reverse(uf))
(%i2) unitfrac (9/10); 1 1 1 (%o2) [-, -, --] 2 3 15
(%i3) apply ("+", %); 9 (%o3) -- 10
(%i4) unitfrac (-9/10); 1 (%o4) [- 1, --] 10
(%i5) apply ("+", %); 9 (%o5) - -- 10
(%i6) unitfrac (36/37); 1 1 1 1 1 (%o6) [-, -, -, --, ----] 2 3 8 69 6808
(%i7) apply ("+", %); 36 (%o7) -- 37
‘Category: Mathematical functions’
Returns the largest integer less than or equal to x where x is
numeric. fix
(as in fixnum
) is a synonym for this, so
fix(x)
is precisely the same.
‘Category: Mathematical functions’
When x is a real number, return the largest integer that is less than or equal to x.
If x is a constant expression (10 * %pi
, for example), floor
evaluates x using big floating point numbers, and applies floor
to
the resulting big float. Because floor
uses floating point evaluation,
it’s possible, although unlikely, that floor
could return an erroneous
value for constant inputs. To guard against errors, the floating point
evaluation is done using three values for fpprec
.
For non-constant inputs, floor
tries to return a simplified value. Here
are examples of the simplifications that floor
knows about:
(%i1) floor (ceiling (x)); (%o1) ceiling(x)
(%i2) floor (floor (x)); (%o2) floor(x)
(%i3) declare (n, integer)$
(%i4) [floor (n), floor (abs (n)), floor (min (n, 6))]; (%o4) [n, abs(n), min(6, n)]
(%i5) assume (x > 0, x < 1)$
(%i6) floor (x); (%o6) 0
(%i7) tex (floor (a)); $$\left \lfloor a \right \rfloor$$ (%o7) false
The floor
function distributes over lists, matrices and equations.
See distribute_over
.
Finally, for all inputs that are manifestly complex, floor
returns
a noun form.
If the range of a function is a subset of the integers, it can be declared to
be integervalued
. Both the ceiling
and floor
functions
can use this information; for example:
(%i1) declare (f, integervalued)$
(%i2) floor (f(x)); (%o2) f(x)
(%i3) ceiling (f(x) - 1); (%o3) f(x) - 1
‘Category: Mathematical functions’
A synonym for entier (x)
.
‘Category: Mathematical functions’
The Heaviside unit step function, equal to 0 if x is negative, equal to 1 if x is positive and equal to 1/2 if x is equal to zero.
If you want a unit step function that takes on the value of 0 at x
equal to zero, use unit_step
.
‘Category: Laplace transform’ ‘Category: Mathematical functions’
When L is a list or a set, return apply ('max, args (L))
.
When L is not a list or a set, signal an error.
See also lmin
and max
.
‘Category: Mathematical functions’ ‘Category: Lists’ ‘Category: Sets’
When L is a list or a set, return apply ('min, args (L))
.
When L is not a list or a set, signal an error.
See also lmax
and min
.
‘Category: Mathematical functions’ ‘Category: Lists’ ‘Category: Sets’
Return a simplified value for the maximum of the expressions x_1 through
x_n. When get (trylevel, maxmin)
, is 2 or greater, max
uses the simplification max (e, -e) --> |e|
. When
get (trylevel, maxmin)
is 3 or greater, max tries to eliminate
expressions that are between two other arguments; for example,
max (x, 2*x, 3*x) --> max (x, 3*x)
. To set the value of trylevel
to 2, use put (trylevel, 2, maxmin)
.
‘Category: Mathematical functions’
Return a simplified value for the minimum of the expressions x_1
through
x_n
. When get (trylevel, maxmin)
, is 2 or greater, min
uses the simplification min (e, -e) --> -|e|
. When
get (trylevel, maxmin)
is 3 or greater, min
tries to eliminate
expressions that are between two other arguments; for example,
min (x, 2*x, 3*x) --> min (x, 3*x)
. To set the value of trylevel
to 2, use put (trylevel, 2, maxmin)
.
‘Category: Mathematical functions’
When x is a real number, returns the closest integer to x.
Multiples of 1/2 are rounded to the nearest even integer. Evaluation of
x is similar to floor
and ceiling
.
The round
function distributes over lists, matrices and equations.
See distribute_over
.
‘Category: Mathematical functions’
For either real or complex numbers x, the signum function returns
0 if x is zero; for a nonzero numeric input x, the signum function
returns x/abs(x)
.
For non-numeric inputs, Maxima attempts to determine the sign of the input.
When the sign is negative, zero, or positive, signum
returns -1,0, 1,
respectively. For all other values for the sign, signum
a simplified but
equivalent form. The simplifications include reflection (signum(-x)
gives -signum(x)
) and multiplicative identity (signum(x*y)
gives
signum(x) * signum(y)
).
The signum
function distributes over a list, a matrix, or an
equation. See sign
and distribute_over
.
‘Category: Mathematical functions’
When x is a real number, return the closest integer to x not
greater in absolute value than x. Evaluation of x is similar
to floor
and ceiling
.
The truncate
function distributes over lists, matrices and equations.
See distribute_over
.
‘Category: Mathematical functions’
Next: Functions for Complex Numbers, Previous: Mathematical Functions, Up: Mathematical Functions [Contents][Index]