Re: Sorting complex points
- To: mathgroup at smc.vnet.net
- Subject: [mg55893] Re: [mg55874] Sorting complex points
- From: "David Park" <djmp at earthlink.net>
- Date: Sat, 9 Apr 2005 03:55:35 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Andrea,
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.
Arg[clist]
{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 earthlink.net
http://home.earthlink.net/~djmp/
From: OT [mailto:montoz at iol.it]
To: mathgroup at smc.vnet.net
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...
Thanks,
andrea