abs
Computes absolute values.
Syntax
-
abs(x)
-
x
is a number, vector, or matrix
-
Description
If x
is a real or complex number, abs(x)
is the absolute value of x
.
-
For real
x
,abs(x)
isx
ifx ≥ 0
and−x
otherwise. Ifx
is of type integer or rational number, so isabs(x)
. -
For complex
z = a + b⋅i
(witha
andb
real),abs(z)
is√(a² + b²)
. The type ofabs(z)
is real number.
If x
is a vector or a matrix, abs(x)
is the vector or matrix obtained by taking element-wise absolute values. abs(x)
is always a real vector or matrix, even if x
is a complex vector or matrix.
Examples
abs(10)
10
abs(−10)
10
abs(3 + 4⋅i)
5
abs(❨1, −1, 0❩)
⎛1⎞ e⎜1⎟ ⎝0⎠
abs(❨❨1, i❩, ❨−i, −2❩❩)
⎛1 1⎞ ⎝1 2⎠