help-octave
[Top][All Lists]

## Re: cplxpair question

 From: Ozzy Lash Subject: Re: cplxpair question Date: Sun, 22 Jan 2017 18:54:02 -0600

On Sun, Jan 15, 2017 at 9:28 PM, Ozzy Lash wrote:
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.

Can someone with matlab run the script to verify my assumption that the results for octave are incorrect?  If so I'll report it at savannah, and try coming up with a fix.

Bill

I have reported this as a bug, with a proposed patch at savannah it is bug 50124 https://savannah.gnu.org/bugs/index.php?50124

Bill

reply via email to