MATLAB: When I take the integer root of a complex number, which root will MATLAB return

complexintegerMATLABroot

When I take the integer root of a complex number, which root will MATLAB return?
There are "n" roots that are a solution to "r = z^(1/n)". How can I anticipate which root will be returned?

Best Answer

MATLAB returns the root closest to the positive x-axis. This corresponds to the root with smallest absolute phase angle as returned by the ANGLE function.
When there are two roots symmetric about the x-axis (as is the case for a negative real number or a pure imaginary number), MATLAB returns the root with a positive imaginary part.
To obtain all "n" roots of the complex number "z", use the commands:
P = -1;P(n+1) = z;
r = roots(P)
or
k=1:n;
y = abs(z)^(1/n)*exp(i/n*(angle(z)+2*k*pi))
or
y2 = z^(1/n);
y2 = abs(y2)*exp(i*(angle(y2)+2*[1:n]*pi/n))
The results "y" and "y2" will be identical.
When "z" is a matrix of complex values, use the commands:
[z k] = meshgrid(z,1:n);
y = abs(z).^(1/n).*exp(i/n*(angle(z)+2*k*pi))
or
[z k] = meshgrid(z,1:n);
y2 = z.^(1/n);
y2 = abs(y2).*exp(i*(angle(y2)+2*k*pi/n))
Again, the results "y" and "y2" will be identical.