Accelerating the pace of engineering and science

sign

Sign of real or complex value

Description

example

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.

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 + (2*i)/5),                             -1]
[   2^(1/2)*(- 1/2 + i/2), 5^(1/2)*18^(1/2)*(1/30 - i/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:

`syms x clear`

Input Arguments

expand all

z — Inputsymbolic number | symbolic variable | symbolic expression | symbolic function | symbolic vector | symbolic matrix

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

expand all

Sign Function

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

$\mathrm{sign}\left(z\right)=\frac{z}{|z|}$

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

Tips

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