Sort complex vectors in specific order

放肆的年华 提交于 2019-12-25 09:34:00

问题


I have vector with eigenvalues:

e = 

-0.4094 + 3.9387i
-0.4094 - 3.9387i
-0.0156 + 0.5645i
-0.0156 - 0.5645i

And I would like to sort this vector like that:

e_sort =

-0.0156 + 0.5645i
-0.4094 + 3.9387i
-0.0156 - 0.5645i
-0.4094 - 3.9387i

The rule is: First must be:

 -a+b*i

and then:

 -a-b*i

We can say, that:

  0 < b_1 < b_2 < ... < b_n

Thanks,


回答1:


e1 = e(imag(e) >= 0);
e2 = e(imag(e) < 0);
newe = cat(1,sort(e1),sort(e2))

newe =

-0.0156 + 0.5645i
-0.4094 + 3.9387i
-0.0156 - 0.5645i
-0.4094 - 3.9387i


来源:https://stackoverflow.com/questions/27090398/sort-complex-vectors-in-specific-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!