# What does it mean to take the absolute of an complex number? And why is it always positive?

16 views (last 30 days)

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!

##### 0 Comments

### Accepted Answer

Steven Lord
on 26 Apr 2022

I think one potential source of confusion is that the abs of this particular complex number looks an awful lot like its real part.

n = -0.993061325012476 + 1.03511742045580e-16i;

R = abs(n)

That's not due to abs simply taking the real part of the complex number, it's due to the fact that the imaginary part of this number is extremely small. If you were to plot this number you'd see that it's very close to being on the real line.

setupFigure();

% This plots using the real part of n as the x coordinate

% and the imaginary part of n as the y coordinate. I made the marker

% larger so it stands out

plot(n, 'bo', 'MarkerSize', 10)

If we plotted another point, one whose real and imaginary parts were both not small, you'd see the abs of that number was the distance between it and the origin. For the point n2 the red dotted line is the line whose length is measured by taking abs(n2).

setupFigure();

n2 = 1+1i;

plot(n, 'bo', 'MarkerSize', 10)

plot(n2, 'ks', 'MarkerSize', 10)

plot([0 n2], 'r:', 'LineWidth', 2)

fprintf("The red dotted line is %g units long.\n", abs(n2)) % sqrt(2)

function setupFigure()

% Set up the plot to look nice

figure

axes('XAxisLocation', 'origin', 'YAxisLocation', 'origin')

axis([-1, 1, -1, 1])

xlabel('real(n)')

ylabel('imag(n)')

xticks(-1:0.25:1)

yticks(-1:0.25:1)

grid on

hold on

end

##### 0 Comments

### More Answers (2)

Torsten
on 25 Apr 2022

##### 2 Comments

Torsten
on 26 Apr 2022

Why should anything change ?

z=x+i*y is a static point in the x-y plane. If you interprete C as R^2, then this point z is P=(x/y). And abs(z) returns the distance of P from (0/0), thus sqrt(x^2+y^2).

Walter Roberson
on 26 Apr 2022

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

Walter Roberson
on 26 Apr 2022

### See Also

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!