sign
Sign of a real or complex number
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
sign(z
)
sign(z)
returns the sign of the number z
.
Mathematically, the sign of a complex number z ≠ 0 is defined as . For real numbers, this reduces to 1 or  1.
sign()
and sign(0.0)
return 0
.
The user may redefine this value by a direct assignment, e.g.:
unprotect(sign): sign(0) := 1: protect(sign):
If the type of z
is DOM_INT
, DOM_RAT
,
or DOM_FLOAT
,
a fast kernel function is used to determine the sign. The return value
is either  1, 0,
or 1.
If the sign of the expression cannot be determined, a symbolic function call is returned. Certain simplifications are implemented. In particular, numerical factors of symbolic products are simplified. Cf. Example 2.
The expand
function
rewrites the sign of a product to a product of signs. E.g., expand(sign(x*y))
yields sign(x)*sign(y)
.
Cf. Example 2.
For constant expressions such as PI  sqrt(2)
, exp(I*3)
 I*sin(3)
etc., internal floatingpoint evaluation is used
to determine, whether the expression represents a nonzero real number.
If so, the sign  1 or 1 is
returned. Internally, the floatingpoint approximation is checked
for reliability. Cf. Example 4.
sign
respects properties of
identifiers. For real expressions, the result may depend on the value
of the environment variable DIGITS
.
We compute the sign of various real numbers and expressions:
sign(8/3), sign(3.2), sign(exp(3)  sqrt(2)*PI), sign(0)
The sign of a complex number z
is the complex
number z/abs(z)
:
sign(0.5 + 1.1*I), sign(2 + 3*I), sign(exp(sin(2 + 3*I)))
sign
yields a symbolic, yet simplified, function
call if identifiers are involved:
sign(x), sign(2*x*y), sign(2*x + y), sign(PI*exp(2 + y))
In special cases, the expand
function
may provide further simplifications:
expand(sign(2*x*y)), expand(sign(PI*exp(2 + y)))
sign
respects properties of identifiers:
sign(x + PI)
assume(x > 3): sign(x + PI)
unassume(x):
The following rational number approximates π to about 30 digits:
p:= 39269908169872415480783042291/12500000000000000000000000000:
With the standard precision DIGITS =10
, the
float test inside sign
does not give a decisive
answer, whether p
is larger or smaller than π:
float(PI  p)
This result is subject to numerical roundoff and does not allow
a conclusion on the sign of the number PI  p
.
The float test inside sign
checks the reliablity
of floatingpoint approximations. In this case, no simplified result
is returned:
sign(PI  p)
With increased DIGITS
, a reliable decision can be taken:
DIGITS := 30: sign(PI  p)
delete p, DIGITS:

Arithmetical expression.
z