Sort a numerical list
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
numeric::sort(list) sorts the elements in
The elements of the list are sorted such that their real parts are descending. Elements with the same real part are sorted from large absolute value to small absolute value. In case of a tie (i.e., two elements form a complex conjugate pair), the element with positive imaginary part comes first.
The elements of the list are converted to floating-point numbers
that cannot be converted lead to an error.
The function is sensitive to the environment variable
The elements in the sorted list have descending real parts:
numeric::sort([1, 2.0, I, -3, -I, PI, sqrt(2)])
In the following example, the sorting criterion does not seem to be satisfied. Elements with the same real part are supposed to be ordered from large absolute values to small absolute values:
x := sin(PI/3): L := numeric::sort([x, sin(float(PI/3)) - I, x + I])
This is explained by the fact that the floating-point numbers internally have a more accurate representation than shown on the screen. The real part of the last element is indeed a little bit smaller than the other real parts:
DIGITS := 20: L
delete x, L, DIGITS:
A list of numbers or numerical expressions