cplxpairSorting complex numbers into conjugate pairs
cplxpair(A)A is an array of real or complex numbers.eps(1).c1 = a1 + b1*i and c2 = a2 + b2*i form a conjugate pair if abs(a1-a2) and abs(abs(b1) - abs(b2)) are both smaller than the default tolerance max(abs(c1), abs(c2)) * eps(1), and b1 and b2 have opposite signs.a + bi, if a or b is either NaN or Inf, its complex conjugate cannot be paired.A. This happens when, for example, there are odd number of complex numbers.cplxpair(A, [ ], dim)A is as specified in the description above for cplxpair(A).[] means an empty array.dim.dim should be a real positive integer.cplxpair(A, tol)A is as specified in the description above for cplxpair(A).tol is a tolerance used in determining real numbers and conjugate pairs.tol should be a non-negative scalar smaller than 1.tol.c1 = a1 + b1*i and c2 = a2 + b2*i form a conjugate pair if abs(a1-a2) and abs(b1-b2) are both smaller than tol, and b1 and b2 have opposite signs.cplxpair(A, tol, dim)A, tol and dim are as specified in the descriptions above for cplxpair(A), cplxpair(A,[],dim) and cplxpair(A,tol).A along the dim-th dimension using the tolerance tol.a=[-27.62 - 4.075i
-0.014 + 0.032i
-27.62 + 7.557i
-0.014 - 19.00i
28.05 - 0.161i
-27.62 - 7.557i
28.05 - 4.384i
-0.014 + 19.00i
28.05 + 4.384i
26.37 + 0.000i
-0.014 - 0.032i
0.020 + 0.000i
0.005 + 0.000i
-27.62 + 4.075i
28.05 + 0.161i];
cplxpair(a)
ans =
-27.620 - 4.0750i
-27.620 + 4.0750i
-27.620 - 7.5570i
-27.620 + 7.5570i
-0.0140 - 0.0320i
-0.0140 + 0.0320i
-0.0140 - 19.000i
-0.0140 + 19.000i
28.050 - 0.1610i
28.050 + 0.1610i
28.050 - 4.3840i
28.050 + 4.3840i
0.0050 + 0.0000i
0.0200 + 0.0000i
26.370 + 0.0000i
a=[
-0.495 - 0.344i -49.62 - 0.014i
-4.611 + 0.000i -3.663 + 0.000i
0.085 + 0.042i -47.09 - 0.024i
0.029 + 20.22i 0.682 - 10.84i
0.085 - 0.042i -47.09 + 0.024i
0.029 + 0.216i 0.682 - 1.132i
-0.495 + 38.07i -49.62 + 2.114i
0.085 - 4.951i -47.09 + 0.022i
-0.495 - 38.07i -49.62 - 2.114i
0.085 + 4.951i -47.09 - 0.022i
0.522 + 0.000i 1.122 + 0.000i
0.029 - 0.216i 0.682 + 1.132i
-0.495 + 0.344i -49.62 + 0.014i
0.029 - 20.22i 0.682 + 10.84i
-2.575 + 0.000i -37.70 + 0.000i
]'
cplxpair(a,[],2)
a =
Columns 1 through 5:
-0.4950 + 0.3440i -4.6110 + 0.0000i 0.0850 - 0.0420i 0.0290 - 20.220i 0.0850 + 0.0420i
-49.620 + 0.0140i -3.6630 + 0.0000i -47.090 + 0.0240i 0.6820 + 10.840i -47.090 - 0.0240i
Columns 6 through 10:
0.0290 - 0.2160i -0.4950 - 38.070i 0.0850 + 4.9510i -0.4950 + 38.070i 0.0850 - 4.9510i
0.6820 + 1.1320i -49.620 - 2.1140i -47.090 - 0.0220i -49.620 + 2.1140i -47.090 + 0.0220i
Columns 11 through 15:
0.5220 + 0.0000i 0.0290 + 0.2160i -0.4950 - 0.3440i 0.0290 + 20.220i -2.5750 + 0.0000i
1.1220 + 0.0000i 0.6820 - 1.1320i -49.620 - 0.0140i 0.6820 - 10.840i -37.700 + 0.0000i
ans =
Columns 1 through 5:
-0.4950 - 0.3440i -0.4950 + 0.3440i -0.4950 - 38.070i -0.4950 + 38.070i 0.0290 - 0.2160i
-49.620 - 0.0140i -49.620 + 0.0140i -49.620 - 2.1140i -49.620 + 2.1140i -47.090 - 0.0220i
Columns 6 through 10:
0.0290 + 0.2160i 0.0290 - 20.220i 0.0290 + 20.220i 0.0850 - 0.0420i 0.0850 + 0.0420i
-47.090 + 0.0220i -47.090 - 0.0240i -47.090 + 0.0240i 0.6820 - 1.1320i 0.6820 + 1.1320i
Columns 11 through 15:
0.0850 - 4.9510i 0.0850 + 4.9510i -4.6110 + 0.0000i -2.5750 + 0.0000i 0.5220 + 0.0000i
0.6820 - 10.840i 0.6820 + 10.840i -37.700 + 0.0000i -3.6630 + 0.0000i 1.1220 + 0.0000i
a is sorted along the first dimension with tolerance tol = 0.00101. Hence, in the first and second rows of the sorted array, -0.3794973 - 0.4599557i and -0.3784973 + 0.4609557i form a conjugate pair, even though the real parts (and also the imaginary parts) differ by 0.001.a =[
-0.1092265 - 0.0175371i -34.228177 + 4.7641329i
-0.0308166 + 0.0000000i -0.1631809 + 0.0000000i
-0.1102265 + 0.0185371i -34.229177 - 4.7631329i
2.4420461 - 0.0238848i 0.1105287 - 0.1661568i
2.4430461 + 0.0248848i 0.1115287 + 0.1671568i
-0.1102265 - 0.0621998i -34.229177 - 41.254490i
47.129957 + 0.0000000i 0.4034812 + 0.0000000i
-3.6544816 + 0.0000000i 0.0116494 + 0.0000000i
2.4420461 - 1.7635095i 0.1105287 - 0.5415976i
-0.1102265 + 0.0621998i -34.229177 + 41.254490i
2.4420461 + 1.7635095i 0.1105287 + 0.5415976i
-0.3794973 - 0.4599557i 4.7495474 + 5.9845691i
-0.3794973 - 4.1173533i 4.7495474 + 0.1136352i
-0.3784973 + 0.4609557i 4.7505474 - 5.9835691i
-0.3794973 + 4.1173533i 4.7495474 - 0.1136352i
]
cplxpair(a,0.00101)
a =
-0.1092 - 0.0175i -34.228 + 4.7641i
-0.0308 + 0.0000i -0.1632 + 0.0000i
-0.1102 + 0.0185i -34.229 - 4.7631i
2.4420 - 0.0239i 0.1105 - 0.1662i
2.4430 + 0.0249i 0.1115 + 0.1672i
-0.1102 - 0.0622i -34.229 - 41.254i
47.130 + 0.0000i 0.4035 + 0.0000i
-3.6545 + 0.0000i 0.0116 + 0.0000i
2.4420 - 1.7635i 0.1105 - 0.5416i
-0.1102 + 0.0622i -34.229 + 41.254i
2.4420 + 1.7635i 0.1105 + 0.5416i
-0.3795 - 0.4600i 4.7495 + 5.9846i
-0.3795 - 4.1174i 4.7495 + 0.1136i
-0.3785 + 0.4610i 4.7505 - 5.9836i
-0.3795 + 4.1174i 4.7495 - 0.1136i
ans =
-0.3795 - 0.4600i -34.229 - 4.7631i
-0.3785 + 0.4610i -34.228 + 4.7641i
-0.3795 - 4.1174i -34.229 - 41.254i
-0.3795 + 4.1174i -34.229 + 41.254i
-0.1092 - 0.0175i 0.1105 - 0.1662i
-0.1102 + 0.0185i 0.1115 + 0.1672i
-0.1102 - 0.0622i 0.1105 - 0.5416i
-0.1102 + 0.0622i 0.1105 + 0.5416i
2.4420 - 0.0239i 4.7495 - 0.1136i
2.4430 + 0.0249i 4.7495 + 0.1136i
2.4420 - 1.7635i 4.7505 - 5.9836i
2.4420 + 1.7635i 4.7495 + 5.9846i
-3.6545 + 0.0000i -0.1632 + 0.0000i
-0.0308 + 0.0000i 0.0116 + 0.0000i
47.130 + 0.0000i 0.4035 + 0.0000i