cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Sorting complexes

AlvaroDíaz
9-Granite

Sorting complexes

There are no way to sort complexes, the order relation isn't defined over the field of complexes.

But mathcad do something with they



Reading the help: sort(v): Returns a vector with the values from v sorted in ascending order. one can be convinced that this is a bug. Question is that I don't understand very well which rules follow sort with complex elements in vectors.

Regards. Alvaro.
10 REPLIES 10

From my help for sort:

>>If v or A contain complex elements, the imaginary part is ignored. <<
__________________
� � � � Tom Gutman

Thanks Tom. Not in mine: only says something about ORIGIN and reversing the order, that's under help contents/functions/Built-in functions/Sorting/sort.

Regards. Alvaro.

M14 Help says that sort() uses only the real part, but this surfaces the issue of the value of sorting complex numbers at all. I guess that M must have /some/ rule, but unfortunately |z| can take on many forms, and some z1 whose Re(z1) < Re(z2) may actually be |z1| > |z2|.

MATLAB addresses this pretty completely, so at least you know what is happening. When A is complex, the elements are sorted by magnitude, i.e., |A|, and where magnitudes are equal, further sorted by phase angle, i.e., angle(A), on the interval -pi..pi. If A includes any NaN elements, sort places these at the high end.

I don't recall trying this in Maple...

Rich
http://www.downeastengineering.com/

If the complex variable is stored as real parts and imaginary parts in a matrix, then sorting is straightforward.

On 12/19/2009 11:11:56 AM, study wrote:
== If the complex variable is stored as real parts
and imaginary parts in a matrix, then sorting is
straightforward.

or possibly defining a sort function that allows
the user to plug in their own ordering predicate.

Stuart

Very complete and useful work. Unfortunately I can't find theoretical background about sorting complexes, my knowledge stops at the event "don't try because is not possible". Possible or not, is very practical.

Regards. Alvaro.

On 12/20/2009 2:42:56 AM, adiaz wrote:
== Very complete and useful work.

Thanks, but it's not complete - it might well be
desirable to sort by im then re, or by arg then
modulus. Or even by one attribute alone if the
order of the other attribute should be maintained
(mergesort is a stable sort (appropriate for this
time of year) and will won't change the order of
elements if the main attributes are equal).

== Unfortunately I can't find theoretical
background about sorting complexes, my knowledge
stops at the event "don't try because is not
possible". Possible or not, is very practical.

They can be sorted, IIRC re-then-im and mod-then-
arg are both total orderings, but complex numbers
aren't generally regarded as orderable because
simple operations, such as addition and
multiplication, do not preserve the order as they
would when applied to reals.

Stuart


On 12/20/2009 2:33:07 PM, stuartafbruff wrote:

>Thanks, but it's not complete - it might well be desirable to sort by im then re, or by arg then modulus.

OK, but it's complete in the sense that you refer how other programs order complexes (including derive!).

>They can be sorted, IIRC re-then-im and mod-then-arg are both total orderings, but complex numbers aren't generally regarded as orderable because simple operations, such as addition and multiplication, do not preserve the order as they would when applied to reals.

You're right, complexes by itself can be sorted, but what have not order relation is the corp. In this page can find the demonstration:

http://fr.wikipedia.org/wiki/Corps_ordonn�

Corp (field) is the structure that have complexes, and this is what I refer as unsorted. The total order without the structure, for this is for what I have not idea about theoretical background: can be sorted, so: for what?

The classification of order relations is



This from the spanish wiki page http://es.wikipedia.org/wiki/Orden_total , the schema isn't in english.

Regards. Alvaro.

I have problems sorting polynomials roots, each procedure (solve, polyroots, eigenvalues) sorts its different, and the same procedure sorts different symbolic answers. As consequence never know which roots it's to be used.

Regards. Alvaro.

"I have problems sorting polynomials roots,... As consequence never know which roots it's to be used.
_________________________

Does not matter knowing or not, all roots are being used. The reconstruct is via the Lagrange iterated product, no matter the order, however there is a Mathcad/Maple symbolic extract in ascending order. I'm saying the same as Rich & Theodore but in different words. Look back at the cubic root that was posted many times.

jmG


Top Tags