What does it mean to take the absolute of an complex number? And why is it always positive?
Show older comments
Hi,
I have a number which is part imaginary or complex.
-0.993061325012476 + 1.03511742045580e-16i
When I use the function abs(x) on this number like so:
abs(-0.993061325012476 + 1.03511742045580e-16i)
ans =
0.99306
Then I receive a positive number.
Can someone kindly explain to me how this works and if the abs(x) function makes it positive or if the abs(x) function simply never returns negative numbers. If so why?
Or is it maybe the case that I need to be better versed in complex numbers in general?
Thanks!
Accepted Answer
More Answers (2)
Torsten
on 25 Apr 2022
1 vote
abs(z) where z=x+i*y is the distance of the point (x/y) from the point (0/0), thus always >=0 and =0 only if z = 0.
syms a b real
c = a + b*1i
d = abs(c)
With the real and imaginary components each being real, their squares are going to be non-negative numbers, and the sum of non-negative numbers is non-negative, and the square root of a non-negative number is non-negative
5 Comments
lil brain
on 26 Apr 2022
lil brain
on 26 Apr 2022
Walter Roberson
on 26 Apr 2022
The abs() function does the calculation shown for complex values, except possibly it might internally use hypot() for better accuracy with small values.
Walter Roberson
on 26 Apr 2022
Edited: Walter Roberson
on 26 Apr 2022
absolute value is the Euclidean magnitude function. If you represent the points as ordered tuples of components, < x1, x2, x3,... xn > for a vector in n dimensions, then absolute value is sqrt(sum of (x(K)^2), K=1 to n). In the case of complex numbers which you could represent as the tuple < xreal, ximaginary > then sqrt(xreal^2 + ximaginary^2)
This is a formal Distance, and formal Distance are never negative.
Perhaps you might be wondering about the actual implementation. The actual implementation for scalar real IEEE floating point values is delegated to hardware. The algorithm is
1. check if the value represents NaN. If it does then the result is the same as the input 2. Otherwise, zero the most significant bit of the IEEE representation of the number. This works even for infinity and negative zero.
IEEE floating point representation uses "separate sign" which is 0 for non-negative values and 1 for negative values.
At the moment I do not know what the formal algorithm is for IEEE scalar complex values; the model is sqrt of the sum of squares of the components
Walter Roberson
on 26 Apr 2022
For complex numbers, it appears that hypot() is used internally. hypot() is a modified sum of squares algorithm that detects when the squaring would underflow or overflow and uses alternate calculations in those cases.
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
