octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #50124] cplxpair produces incorrect result for


From: Bill Lash
Subject: [Octave-bug-tracker] [bug #50124] cplxpair produces incorrect result for second column of complex pairs
Date: Mon, 23 Jan 2017 00:07:28 +0000 (UTC)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0

URL:
  <http://savannah.gnu.org/bugs/?50124>

                 Summary: cplxpair produces incorrect result for second column
of complex pairs
                 Project: GNU Octave
            Submitted by: welash
            Submitted on: Mon 23 Jan 2017 12:07:27 AM GMT
                Category: Octave Function
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Incorrect Result
                  Status: None
             Assigned to: None
         Originator Name: William Lash
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 4.0.3
        Operating System: GNU/Linux

    _______________________________________________________

Details:

If I understand the documentation for cplxpair correctly, if you pass in a
matrix with 2 columns, the function should sort the pairs in each column
(unless you pass the DIM argument to tell it to sort along the specified
dimension). 

I am seeing that the second column is filled in with values from the first
column.  Here is my test script:

z = exp (2i*pi*[4; 3; 5; 2; 6; 1; 0]/7);
y = [ -1-1i; -1+1i;-3; -2; 1; 2; 3];
[z,y]
cplxpair([z,y])
cplxpair([z,y]) - [z,y]


I get:

>> z = exp (2i*pi*[4; 3; 5; 2; 6; 1; 0]/7);
>> y = [ -1-1i; -1+1i;-3; -2; 1; 2; 3];
>> [z,y]
ans =

  -0.90097 - 0.43388i  -1.00000 - 1.00000i
  -0.90097 + 0.43388i  -1.00000 + 1.00000i
  -0.22252 - 0.97493i  -3.00000 + 0.00000i
  -0.22252 + 0.97493i  -2.00000 + 0.00000i
   0.62349 - 0.78183i   1.00000 + 0.00000i
   0.62349 + 0.78183i   2.00000 + 0.00000i
   1.00000 + 0.00000i   3.00000 + 0.00000i

>> cplxpair([z,y])
ans =

  -0.90097 - 0.43388i  -0.22252 - 0.97493i
  -0.90097 + 0.43388i  -0.22252 + 0.97493i
  -0.22252 - 0.97493i  -0.90097 - 0.43388i
  -0.22252 + 0.97493i  -0.90097 + 0.43388i
   0.62349 - 0.78183i   0.62349 - 0.78183i
   0.62349 + 0.78183i   0.62349 + 0.78183i
   1.00000 + 0.00000i   1.00000 + 0.00000i

>> cplxpair([z,y]) - [z,y]
ans =

   0.00000 + 0.00000i   0.77748 + 0.02507i
   0.00000 + 0.00000i   0.77748 - 0.02507i
   0.00000 + 0.00000i   2.09903 - 0.43388i
   0.00000 + 0.00000i   1.09903 + 0.43388i
   0.00000 + 0.00000i  -0.37651 - 0.78183i
   0.00000 + 0.00000i  -1.37651 + 0.78183i
   0.00000 + 0.00000i  -2.00000 + 0.00000i

>>

looking at the code in cplxpair.m, I am suspicious of a couple of things. 
In:

  [idxi, idxj] = find (abs (imag (z)) ./ (abs (z) + realmin (cls)) < tol);
  q = sparse (idxi, idxj, 1, n, m);
  nr = sum (q, 1);
  [q, idx] = sort (q, 1);
  z = z(idx);
  y = z;

if I take out the semicolons, I see

idx =

   1   3
   2   4
   3   1
   4   2
   5   5
   6   6
   7   7

and then

z(idx) is

z =

  -0.90097 - 0.43388i  -0.22252 - 0.97493i
  -0.90097 + 0.43388i  -0.22252 + 0.97493i
  -0.22252 - 0.97493i  -0.90097 - 0.43388i
  -0.22252 + 0.97493i  -0.90097 + 0.43388i
   0.62349 - 0.78183i   0.62349 - 0.78183i
   0.62349 + 0.78183i   0.62349 + 0.78183i
   1.00000 + 0.00000i   1.00000 + 0.00000i

I think the indexing for the second column needs  to be relative to the second
column.

Additionally in the loop that does the pairing, the variable j is not used in
indexing the y or z array.






    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?50124>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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