octave-maintainers
[Top][All Lists]
Advanced

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

Re: Socis 16 - Problem with pcg


From: Nicholas Jankowski
Subject: Re: Socis 16 - Problem with pcg
Date: Sun, 3 Jul 2016 09:26:05 -0400


On Jul 3, 2016 8:05 AM, "Nicholas Jankowski" <address@hidden> wrote:
> I.e., is it how we expect other numerical systems, including but not limited to MATLAB,  to handle a complex comparison query?

A quick search shows that my question and yours about how to handle complex comparison is an I'll defined mathematical concept, and the methods are arbitrary. From octave help, they fall back on magnitude as I thought above:

" For complex numbers, the following ordering is defined: z1 < z2 if and only if

abs (z1) < abs (z2) || (abs (z1) == abs (z2) && arg (z1) < arg (z2))

This is consistent with the ordering used by maxmin and sort, but is not consistent with MATLAB, which only compares the real parts."

Regarding how MATLAB handles complex comparisons, here's a bit of an explanation from mathworks help:
"
Complex Numbers

The operators >, <, >=, and <= use only the real part of the operands in performing comparisons.

The operators == and ~= test both real and imaginary parts of the operands.
"
Note that they fall back on the abs val approach for other functions, with a good breakdown here:
http://www.mathworks.com/matlabcentral/newsreader/view_original/182376

As this is fairly basic I would assume it's a known and intended incompatibility.

Apparently R gives an error if you try > or < with a complex argument. Others use lexicographic ordering, following

(a + ib) < (c + id),
provided either a < c or a = c and b < d.

More detail here:
http://www.cut-the-knot.org/do_you_know/complex_compare.shtml

So, other than issues that could creep up regarding MATLAB compatibility of your final code, complex number comparison is an arbitrary choice and just has to produce a consistent result for your usage case. 

Maybe the if (alpha<0) statement maybe should be replaced by something that more accurately reflects the mathematics of the case. Maybe your code path can't depend on alpha but must check the effect of alpha on A, since it seems a bit unpredictable simply based on alpha.


reply via email to

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