assert_sortcomplex — Sort complex numbers in increasing order with a tolerance.
y = assert_sortcomplex ( x ) y = assert_sortcomplex ( x , reltol ) y = assert_sortcomplex ( x , reltol , abstol )
a matrix of doubles, the values to be sorted
a 1x1 matrix of doubles, the relative tolerance (default reltol=sqrt(%eps)).
a 1x1 matrix of doubles, the absolute tolerance (default abstol=0).
a matrix of doubles, the sorted matrix x
This function combines assert_sort with assert_comparecomplex in order to provide a sorting algorithm with numerical comparison based on a mixed relative - absolute criteria.
Compare first by real parts, then by imaginary parts. Takes into account numerical accuracy issues, by using a mixed relative and absolute tolerance criteria.
This function allows to take into account for the portability issues related to the outputs of functions producing matrix of complex doubles. If this algorithm is plugged into a sorting function, it allows to consistently produce a sorted matrix, where the order can be independent of the operating system, the compiler or other forms of issues modifying the order (but not the values).
// Sort realistic data x = [ -0.123452 - 0.123454 * %i -0.123451 + 0.123453 * %i 0.123458 - 0.123459 * %i 0.123456 + 0.123457 * %i ]; // Permute randomly the array n = size(x,"*"); grand("setsd",0); ip = grand(1,"prm",(1:n)'); x = x(ip) // Consider less than 4 significant digits y = assert_sortcomplex(x,1.e-4) // Sort data from bug #415 x = [ -1.9914145 -1.895889 -1.6923826 -1.4815461 -1.1302576 -0.5652256 - 0.0655080 * %i -0.5652256 + 0.0655080 * %i 0.3354023 - 0.1602902 * %i 0.3354023 + 0.1602902 * %i 1.3468911 1.5040136 1.846668 1.9736772 1.9798866 ]; // Permute randomly the array n = size(x,"*"); grand("setsd",0); ip = grand(1,"prm",(1:n)'); x = x(ip) // Consider less than 4 significant digits y = assert_sortcomplex(x,1.e-5)
http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/polynomials/tests/nonreg_tests/bug_415.tst;h=0c716a3bed0dfb72c831972d19dbb0814dffde2b;hb=HEAD
http://gitweb.scilab.org/?p=scilab.git;a=blob_plain;f=scilab/modules/cacsd/tests/nonreg_tests/bug_68.tst;h=920d091d089b61bf961ea9e888b4d7d469942a14;hb=4ce3d4109dd752fce5f763be71ea639e09a12630