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) returns the sign of the number
Mathematically, the sign of a complex number z ≠ 0 is defined as . For real numbers, this reduces to 1 or - 1.
The user may redefine this value by a direct assignment, e.g.:
unprotect(sign): sign(0) := 1: protect(sign):
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.
For constant expressions such as
PI - sqrt(2),
- I*sin(3) etc., internal floating-point evaluation is used
to determine, whether the expression represents a non-zero real number.
If so, the sign - 1 or 1 is
returned. Internally, the floating-point approximation is checked
for reliability. Cf. Example 4.
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
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
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)
The following rational number approximates π to about 30 digits:
With the standard precision
DIGITS =10, the
float test inside
sign does not give a decisive
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 floating-point approximations. In this case, no simplified result
sign(PI - p)
DIGITS, a reliable decision can be taken:
DIGITS := 30: sign(PI - p)
delete p, DIGITS: