Post by Sean2Hi, 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],
Does anyone have a small program to do this?
thank you
Is this what you are looking for?
In[1]:=
data=Table[Random[Complex,{-1-I,1+I}],{10}]
Out[1]//InputForm=
{0.0821271856782817 + 0.2029639541984125*I,
0.06837510881823627 + 0.847443835410322*I,
-0.10011961132922509 - 0.7090021038645318*I,
-0.29863518479415907 - 0.676509694560786*I,
-0.6876398064114924 + 0.9893164268004881*I,
0.35689272889096113 - 0.6162016388396594*I,
-0.47362970566225704 + 0.21374267988832485*I,
-0.1928811783911134 - 0.22833001190101454*I,
-0.4514416407833921 - 0.5575670386850278*I,
-0.8240116837488103 + 0.9290434802764991*I}
In[2]:=
Sort[data,((Re[#1]>Re[#2])&&(Im[#1]>Im[#2]))&]
Out[2]//InputForm=
{-0.8240116837488103 + 0.9290434802764991*I,
0.06837510881823627 + 0.847443835410322*I,
0.0821271856782817 + 0.2029639541984125*I,
-0.1928811783911134 - 0.22833001190101454*I,
-0.4514416407833921 - 0.5575670386850278*I,
-0.47362970566225704 + 0.21374267988832485*I,
0.35689272889096113 - 0.6162016388396594*I,
-0.6876398064114924 + 0.9893164268004881*I,
-0.29863518479415907 - 0.676509694560786*I,
-0.10011961132922509 - 0.7090021038645318*I}
In[3]:=
Sort[data,(Re[#1]>Re[#2])&]
Out[3]//InputForm=
{0.35689272889096113 - 0.6162016388396594*I,
0.0821271856782817 + 0.2029639541984125*I,
0.06837510881823627 + 0.847443835410322*I,
-0.10011961132922509 - 0.7090021038645318*I,
-0.1928811783911134 - 0.22833001190101454*I,
-0.29863518479415907 - 0.676509694560786*I,
-0.4514416407833921 - 0.5575670386850278*I,
-0.47362970566225704 + 0.21374267988832485*I,
-0.6876398064114924 + 0.9893164268004881*I,
-0.8240116837488103 + 0.9290434802764991*I}
In[4]:=
Sort[data,(Im[#1]>Im[#2])&]
Out[4]//InputForm=
{-0.6876398064114924 + 0.9893164268004881*I,
-0.8240116837488103 + 0.9290434802764991*I,
0.06837510881823627 + 0.847443835410322*I,
-0.47362970566225704 + 0.21374267988832485*I,
0.0821271856782817 + 0.2029639541984125*I,
-0.1928811783911134 - 0.22833001190101454*I,
-0.4514416407833921 - 0.5575670386850278*I,
0.35689272889096113 - 0.6162016388396594*I,
-0.29863518479415907 - 0.676509694560786*I,
-0.10011961132922509 - 0.7090021038645318*I}
In[5]:=
data=Chop[Table[(n+\[ImaginaryI] n),{n,-1,1,0.2}]]
Out[5]//InputForm=
{-1 - I, -0.8 - 0.8*I, -0.6 - 0.6*I,
-0.39999999999999997 - 0.39999999999999997*I,
-0.19999999999999996 - 0.19999999999999996*I, 0,
0.20000000000000007 + 0.20000000000000007*I,
0.4000000000000001 + 0.4000000000000001*I,
0.6000000000000001 + 0.6000000000000001*I,
0.8 + 0.8*I, 1. + 1.*I}
In[6]:=
Sort[data,((Re[#1]>Re[#2])&&(Im[#1]>Im[#2]))&]
Out[6]//InputForm=
{1. + 1.*I, 0.8 + 0.8*I, 0.6000000000000001 +
0.6000000000000001*I, 0.4000000000000001 +
0.4000000000000001*I, 0.20000000000000007 +
0.20000000000000007*I, 0, -0.19999999999999996 -
0.19999999999999996*I, -0.39999999999999997 -
0.39999999999999997*I, -0.6 - 0.6*I, -0.8 - 0.8*I,
-1 - I}
Best regards,
/J.M.