2026a
# cplxpair
将复数排序为复共轭对组
# 语法
B = cplxpair(A)
B = cplxpair(A,tol)
B = cplxpair(A,[],dim)
B = cplxpair(A,tol,dim)
# 说明
B = cplxpair(A) 对沿复数数组不同维度的元素排序,并将复共轭对组组合在一起。
共轭对组按递增实部排序。在对组中,带有负虚部的元素排在前面。在所有复数对组后返回纯实数值。复共轭对组会强制成为精确复共轭。相对于 100*eps 的默认容差 abs(A(i)) 确定哪些数字是实数,哪些元素是成对复共轭。
如果 A 为向量,cplxpair(A) 返回复共轭对组组合在一起的 A。
如果 A 是矩阵,则 cplxpair(A) 返回其列已排序且复共轭已配对的 A。
如果 A 为多维数组,cplxpair(A) 将沿着第一个非单一维的值视为向量,返回排序元素数组。
B = cplxpair(A,tol) 覆盖默认容差。
B = cplxpair(A,[],dim) 沿着标量 dim 指定的维度对 A 排序。
B = cplxpair(A,tol,dim) 沿着指定维度对 A 排序并覆盖默认容差。
# 示例
示例一
using TyMath
rng = MT19937ar(5489)
a = rand(rng, 100)
b = rand(rng, 100)
a1 = a + b * im
a2 = a - b * im
z = [a1; a2]
inds = randperm(rng, 200)
z = z[inds]
r1 = cplxpair(z)
r1 = 200-element Vector{ComplexF64}:
0.011902069501241397 - 0.8176277083222621im
0.011902069501241397 + 0.8176277083222621im
0.031832846377420676 - 0.9106475944295229im
0.031832846377420676 + 0.9106475944295229im
⋮
0.9648885351992765 - 0.7481515928237095im
0.9648885351992765 + 0.7481515928237095im
0.9705927817606157 - 0.08382137799693257im
0.9705927817606157 + 0.08382137799693257im
# 诊断
如果有奇数个复数,或者这些复数无法在容差范围内组合为复共轭对组,则 cplxpair 生成错误消息:Complex numbers can't be paired。