Sort the numbers z into complex conjugate pairs ordered by increasing real part. With identical real parts, order by increasing imaginary magnitude. Place the negative imaginary complex number first within each pair. Place all the real numbers after all the complex pairs (those with
abs (imag (
z) /
z) <
tol)
, where the default value of tol is100 *
eps.By default the complex pairs are sorted along the first non-singleton dimension of z. If dim is specified, then the complex pairs are sorted along this dimension.
Signal an error if some complex numbers could not be paired. Requires all complex numbers to be exact conjugates within tol, or signals an error. Note that there are no guarantees on the order of the returned pairs with identical real parts but differing imaginary parts.
cplxpair (exp(2i*pi*[0:4]'/5)) == exp(2i*pi*[3; 2; 4; 1; 0]/5)
The following code
[ cplxpair(exp(2i*pi*[0:4]'/5)), exp(2i*pi*[3; 2; 4; 1; 0]/5) ]
Produces the following output
ans = -0.80902 - 0.58779i -0.80902 - 0.58779i -0.80902 + 0.58779i -0.80902 + 0.58779i 0.30902 - 0.95106i 0.30902 - 0.95106i 0.30902 + 0.95106i 0.30902 + 0.95106i 1.00000 + 0.00000i 1.00000 + 0.00000i