cplxpair
Sorts complex numbers into conjugate pairs.
Category: Mathematics > Elementary Math
Syntax
Y = cplxpair(Z)
Sorts the elements of Z so that complex conjugates are adjacent, with the real numbers at the end.
Description
The function is meant for arrays that should be conjugate-symmetric, such as the roots of a polynomial with real coefficients. It checks that every complex value has a partner and puts it next to it, with the member that has the negative imaginary part first.
If some complex element has no conjugate within a small tolerance, the call fails with an error.
Input arguments
Z- Vector (or array) whose complex elements occur in conjugate pairs.
Output arguments
Y- Sorted array. Each pair has the negative imaginary part first. Pairs are ordered by increasing real part, then real values in ascending order.
Example
Grouping conjugate pairs
cplxpair([3 1+2i 1-2i])
cplxpair([2+1i 5 2-1i 3-4i 3+4i])
Output
ans = 1×3 complex
1.0000 - 2.0000i 1.0000 + 2.0000i 3.0000 + 0.0000i
ans = 1×5 complex
2.0000 - 1.0000i 2.0000 + 1.0000i 3.0000 - 4.0000i 3.0000 + 4.0000i 5.0000 + 0.0000i