MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Sorting complex points


unitcomplex[angle_] := Cos[angle] + I Sin[angle]

Here is a list of unit modulus complex numbers using the definition. Notice
that Mathematica evaluates them.

clist = MapThread[unitcomplex,
   {{Pi/2, Pi/4, (-2/3)*Pi, -Pi/4}}]
{I, (1 + I)/Sqrt[2], -(1/2) - (I*Sqrt[3])/2,
  (1 - I)/Sqrt[2]}

Here are the arguments of the numbers. The arguments are between -Pi and Pi.

{Pi/2, Pi/4, -((2*Pi)/3), -(Pi/4)}

We can then sort using the Arg function to write a sorting criterion as the
second argument of Sort.

Sort[clist, Arg[#1] <= Arg[#2] &]
{-(1/2) - (I*Sqrt[3])/2, (1 - I)/Sqrt[2],
  (1 + I)/Sqrt[2], I}

Another example...

clist2 = MapThread[unitcomplex, {{22.1°, -11.3°, 45.65°, -73°}}]
{0.9265286308718373 + 0.37622426313936563*I,
  0.980614658546613 - 0.19594614424251772*I,
  0.69903957914671 + 0.7150829789516673*I,
  Cos[73*Degree] - I*Sin[73*Degree]}

Sort[clist2, Arg[#1] <= Arg[#2] & ]
{Cos[73*Degree] - I*Sin[73*Degree],
  0.980614658546613 - 0.19594614424251772*I,
  0.9265286308718373 + 0.37622426313936563*I,
  0.69903957914671 + 0.7150829789516673*I}

This would look better if we defined...

unitcomplex2[angle_] := Exp[angle I]

clist = MapThread[unitcomplex2,
   {{Pi/2, Pi/4, (-2/3)*Pi, -Pi/4}}]
{I, E^((I*Pi)/4), E^(-((2*I*Pi)/3)), E^(-((I*Pi)/4))}

Sort[clist, Arg[#1] <= Arg[#2] & ]
{E^(-((2*I*Pi)/3)), E^(-((I*Pi)/4)), E^((I*Pi)/4), I}

David Park
djmp at

From: OT [mailto:montoz at]
To: mathgroup at

Hi all,

I'm trying to sort lists of random complex points on the unit circle
using their angles as criterion to sort them: I mean, if
z=Cos[a]+I*Sin[a] and w=Cos[b]+I*Sin[b]( 0<=a,b<2*Pi ),
I want z<w if a<b;

how can i do that?

I tried to define Angle[z] as a piecewise funztion, but I still don't
understand how to use it with Sort...



  • Prev by Date: simplified C API call in MathLink
  • Next by Date: Re: Replacement gyrations
  • Previous by thread: Re: Sorting complex points
  • Next by thread: Re: Sorting complex points