Accelerating the pace of engineering and science

abs

Absolute value and complex magnitude

Description

example

Y = abs(X) returns the absolute value of each element in array X.

If X is complex, abs(X) returns the complex magnitude.

Examples

expand all

Absolute Value of Scalar

`y = abs(-5)`
```y =

5```

Absolute Value of Vector

Create a numeric vector of real values.

`x = [1.3 -3.56 8.23 -5 -0.01]'`
```x =

1.3000
-3.5600
8.2300
-5.0000
-0.0100```

Find the absolute value of the elements of the vector.

`y = abs(x)`
```y =

1.3000
3.5600
8.2300
5.0000
0.0100```

Magnitude of Complex Number

`y = abs(3+4i)`
```y =

5```

Input Arguments

expand all

X — Input arrayscalar | vector | matrix | multidimensional array

Input array, specified as a scalar, vector, matrix, or multidimensional array. X can be a single array, double array, signed integer array, or duration array. The size and data type of the output array is the same as the input array.

Complex Number Support: Yes

expand all

Absolute Value

The absolute value (or modulus) of a real number is the corresponding nonnegative value that disregards the sign.

For a real value, a, the absolute value is:

• a, if a is greater than or equal to zero

• -a, if a is less than zero

abs(-0) returns 0.

Complex Magnitude

The complex magnitude (or modulus) is the length of a vector from the origin to a complex value plotted in the complex plane.

For a complex value, $|a+bi|$ is defined as $\sqrt{{a}^{2}+{b}^{2}}$.