Main Content

sign

Sign of real or complex value

Syntax

Description

sign(z) returns the sign of real or complex value z. The sign of a complex number z is defined as z/abs(z). If z is a vector or a matrix, sign(z) returns the sign of each element of z.

example

Examples

Signs of Real Numbers

Find the signs of these symbolic real numbers:

[sign(sym(1/2)), sign(sym(0)), sign(sym(pi) - 4)]
ans =
[ 1, 0, -1]

Signs of Matrix Elements

Find the signs of the real and complex elements of matrix A:

A = sym([(1/2 + i), -25; i*(i + 1), pi/6 - i*pi/2]);
sign(A)
ans =
[   5^(1/2)*(1/5 + 2i/5),                              -1]
[ 2^(1/2)*(- 1/2 + 1i/2), 5^(1/2)*18^(1/2)*(1/30 - 1i/10)]

Sign of Symbolic Expression

Find the sign of this expression assuming that the value x is negative:

syms x
assume(x < 0)
sign(5*x^3)
ans =
-1

For further computations, clear the assumption on x by recreating it using syms:

syms x

Input Arguments

collapse all

Input specified as a symbolic number, variable, expression, function, vector, or matrix.

More About

collapse all

Sign Function

The sign function of any number z is defined via the absolute value of z:

sign(z)=z|z|

Thus, the sign function of a real number z can be defined as follows:

sign(z)={1 if x<0  0 if x=0  1 if x>0

Tips

  • Calling sign for a number that is not a symbolic object invokes the MATLAB® sign function.

Version History

Introduced in R2013a

See Also

| | | |