From bug-octave-request at bevo dot che dot wisc dot edu Fri Dec 15 12:16:13 2000 Subject: max_complex_arg From: "John W. Eaton" To: Rolf Fabian Cc: "'bug-octave UWISC'" Date: Fri, 15 Dec 2000 12:15:41 -0600 On 15-May-2000, Rolf Fabian wrote: | Hi, | -- Problem 1 -- | max( x ) with complex argument x seems to return max(abs(x)) | actually. If multiple elements with same absolute value are | present, return depends on calling syntax: | | A:) max([1-i,1+i]) | ans = 1 - 1i | B:) max( 1-i,1+i ) | ans = 1 + 1i | | Calling mode 'A' seems always to return SMALLEST (ROW)-INDEX occurence | of multiple elements at same abs, whereas 'B' seems to prefer | LAST occurence in variable arg list. | | I expect both calling modes to return the same thing. OK. I've appended a patch (for the current CVS sources) that should fix this (and, BTW, make it Matlab compatible). | -- Problem 2 -- | The comparison operators '>' '<' etc. seem to simply NEGLECT | the imaginary part if complex numbers involved: | | :) (1+i)>1 | ans = 0 | | :) (1-i)>1 | ans = 0 | :) max([1,1-i,1+i]) | ans = 1 - 1i | | Logically, latest four lines represent a severe contradiction! Perhaps, but I believe that this behavior is Matlab compatible (unless it has changed in Maltab 6). Isn't that what everyone wants?! :-/ Sorry for the long delay. jwe 2000-12-15 John W. Eaton * lo-mappers.cc (xmin (const Complex&, const Complex& y): If args are equal in magnitude, return first arg instead of second. Index: lo-mappers.cc =================================================================== RCS file: /usr/local/cvsroot/octave/liboctave/lo-mappers.cc,v retrieving revision 1.15 diff -u -r1.15 lo-mappers.cc --- lo-mappers.cc 1999/09/10 05:17:01 1.15 +++ lo-mappers.cc 2000/12/15 18:07:58 at @ -315,13 +315,13 @@ Complex xmin (const Complex& x, const Complex& y) { - return abs (x) < abs (y) ? x : (xisnan (x) ? x : y); + return abs (x) <= abs (y) ? x : (xisnan (x) ? x : y); } Complex xmax (const Complex& x, const Complex& y) { - return abs (x) > abs (y) ? x : (xisnan (x) ? x : y); + return abs (x) >= abs (y) ? x : (xisnan (x) ? x : y); } /* ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------