octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting complex values


From: Ben Abbott
Subject: Re: Sorting complex values
Date: Sat, 27 Sep 2014 17:05:36 -0400

On Sep 27, 2014, at 4:29 PM, Daniel J Sebald <address@hidden> wrote:

> On 09/27/2014 02:25 PM, Ben Abbott wrote:
>> 
>> On Sep 27, 2014, at 2:43 PM, Daniel J Sebald<address@hidden>  wrote:
>> 
>>> The one thing that concerns me a bit is that -1 - 0i produces an angle of 
>>> -pi.
>> 
>> I'm confident this behavior is correct. There is a branch along the negative 
>> real axis ... i.e. a phase of +pi and -pi are both correct, but only one of 
>> them is proper by IEEE standards.  To determine the phase it is necessary to 
>> determine if the imaginary part is positive or negative.  The default is to 
>> assume the imaginary part is positive. In the case, of 1 - 0i, the default 
>> has been over-ridden.
> 
> There's a branch cut in the complex plane for the arc-tangent function.  But 
> here it is just numbers represented as modulus and angle
> 
> z = |z|e^jTHETA
>  = |z|e^jTHETA +- N 2pi
> 
> where THETA is the principle argument.  |z|e^jpi and |z|e^-jpi are the same 
> number.  Treating the argument as the principle argument or not, and sorting 
> on it is basically arbitrary.
> 
> I actually prefer to use the principle argument because then the +0/-0 
> phenomenon has no bearing on order, in light of sorting of non-complex 
> numbers which produces:
> 
> octave:70> x = [0 -0 0 -0 0 -0]'
> x =
> 
>   0
>  -0
>   0
>  -0
>   0
>  -0
> 
> octave:71> [s i] = sort(x)
> s =
> 
>   0
>  -0
>   0
>  -0
>   0
>  -0
> 
> i =
> 
>   1
>   2
>   3
>   4
>   5
>   6
> 
> If the +/-0 is meaningless in non-complex sort, then it probably should be 
> meaningless in the complex sort.
> 
> Dan

Ok.  I get the point now.  I happy to run some examples in Matlab if that would 
be useful.

x = [ [1 -1 i -i].' [1 -1 i -i]' ];

sort (x)

ans =

   0.0000 - 1.0000i   0.0000 - 1.0000i
   1.0000 + 0.0000i   1.0000 + 0.0000i
   0.0000 + 1.0000i   0.0000 + 1.0000i
  -1.0000 + 0.0000i  -1.0000 + 0.0000i

Ben





reply via email to

[Prev in Thread] Current Thread [Next in Thread]