Re: sorting complex number?
- To: mathgroup at smc.vnet.net
- Subject: [mg57474] Re: [mg57461] sorting complex number?
- From: Pratik Desai <pdesai1 at umbc.edu>
- Date: Sun, 29 May 2005 01:03:31 -0400 (EDT)
- References: <200505280940.FAA21775@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
>
>
>Hi, I need some help
> I am trying to sort a list of complext number, say, List={a+b*I, c+d*I};
> and I want a>c and b>d. I know that Sort can do this with a small list of complex numbers, but what I deal with is a list of about 100000 and maybe more,
>
>and it doesn't seem to work with the imaginary part when you just Sort[List],
>
>
Try this if you want it to sort it with respect to the imaginary value
values={-0.04484492919995264 - 21.97958759549533*I,
-0.04484492919995265 + 21.979587595495328*I,
-0.16025833149175872 + 18.801523562303874*I,
-0.16025833149175872 - 18.801523562303874*I,
-0.5008914185011427 + 15.633451946906193*I,
-0.5008914185011426 - 15.633451946906193*I,
-0.1751588280975272 + 12.564746566861638*I,
-0.1751588280975272 - 12.564746566861638*I,
-0.04711742781559087 - 9.418500468421371*I,
-0.04711742781559086 + 9.418500468421371*I,
-0.4590555619739296 + 6.232750821142238*I,
-0.4590555619739296 - 6.232750821142238*I,
-0.3331650057325463 + 3.1662410948948874*I,
-0.3331650057325463 - 3.1662410948948874*I}
Sort[values, Abs[Im[#1]] < Abs[Im[#2]] &]
>>{-0.3331650057325463 - 3.1662410948948874*I,
-0.3331650057325463 + 3.1662410948948874*I,
-0.4590555619739296 - 6.232750821142238*I,
-0.4590555619739296 + 6.232750821142238*I,
-0.04711742781559086 + 9.418500468421371*I,
-0.04711742781559087 - 9.418500468421371*I,
-0.1751588280975272 - 12.564746566861638*I,
-0.1751588280975272 + 12.564746566861638*I,
-0.5008914185011426 - 15.633451946906193*I,
-0.5008914185011427 + 15.633451946906193*I,
-0.16025833149175872 - 18.801523562303874*I,
-0.16025833149175872 + 18.801523562303874*I,
-0.04484492919995265 + 21.979587595495328*I,
-0.04484492919995264 - 21.97958759549533*I}
Or you can try something like this
complexsort[list_] := Block[{list1, list2}, list1 = Sort[list, Im[#1] < \
Im[#2] &]; list2 = Sort[Conjugate[list], Im[#1] > Im[#2] &];
> Does anyone have a small program to do this?
> thank you
>
I would be looking forward to it as you are
Best regards
Pratik Desai
Pratik Desai
Graduate Student
UMBC
Department of Mechanical Engineering
Phone: 410 455 8134
- References:
- sorting complex number?
- From: Sean2 <sshiau2@wisc.edu>
- sorting complex number?