Skip to content

cplxpair

general · scripts/general/cplxpair.m

: y = cplxpair (z)
: y = cplxpair (z, tol)
: y = cplxpair (z, tol, dim)

Sort the elements of z into complex conjugate pairs followed by the real numbers.

Each vector along dim (default: first non-singleton dimension) is reordered separately. Complex conjugate pairs come first, ordered by increasing real part (then increasing magnitude of the imaginary part), the member with the negative imaginary part first. The real numbers follow in ascending order.

An element counts as real if abs (imag (z)) <= tol * abs (z); its imaginary part is then set to zero. Two complex elements form a pair if they differ from exact conjugates by at most tol times their magnitude. The default tolerance is 100 * eps. If the complex elements cannot all be paired an error is raised.