Absolute value of a real or complex number
This functionality does not run in MATLAB.
abs(z) returns the absolute value of the number z.
For many constant expressions, abs returns the absolute value as an explicit number or expression. Cf. Example 1.
A symbolic call of abs is returned if the absolute value cannot be determined (e.g., because the argument involves identifiers). The result is subject to certain simplifications. In particular, abs extracts constant factors. Properties of identifiers are taken into account. See Example 2 and Example 3.
In the same way, the absolute value of domain elements can be defined via overloading. Cf. Example 8.
This function is automatically mapped to all entries of container objects such as arrays, lists, matrices, polynomials, sets, and tables.
abs respects properties of identifiers.
For many constant expressions, the absolute value can be computed explicitly:
abs(1.2), abs(-8/3), abs(3 + I), abs(sqrt(-3))
abs(sin(42)), abs(PI^2 - 10), abs(exp(3) - tan(157/100))
abs(exp(3 + I) - sqrt(2))
Symbolic calls are returned if the argument contains identifiers without properties:
abs(x), abs(x + 1), abs(sin(x + y))
The result is subject to some simplifications. In particular, abs splits off constant factors in products:
abs(PI*x*y), abs((1 + I)*x), abs(sin(4)*(x + sqrt(3)))
abs is sensitive to properties of identifiers:
assume(x < 0): abs(3*x), abs(PI - x), abs(I*x)
The expand function produces products of abs calls:
abs(x*(y + 1)), expand(abs(x*(y + 1)))
The absolute value of the symbolic constants PI, EULER, etc. are known:
abs(PI), abs(EULER + CATALAN^2)
Expressions containing abs can be differentiated:
diff(abs(x), x), diff(abs(x), x, x)
The slot "abs" of a function environment f defines the absolute value of symbolic calls of f:
f := funcenv(f): f::abs := x -> f(x)/sign(f(x)): abs(f(x))
The slot "abs" of a domain d defines the absolute value of its elements:
d := newDomain("d"): e1 := new(d, 2): e2 := new(d, x): d::abs := x -> abs(extop(x, 1)): abs(e1), abs(e2)
delete d, e1, e2:
arithmetical expression or a container object containing such expressions