Reputation: 21
Given a list of vectors, I want to sort these vectors in a certain (alphabetic like) order.
For example, the vectors are [5/4, 5/2, 1/3, 2], [1, 5/2, 3/5, 1.5], [5/4, 5/4, 3/5, 1.5] and [5/4, 5/2, 1/4, 2]. We would like to sort them as [1, 5/2, 3/5, 1.5], [5/4, 5/4, 3/5, 1.5], [5/4, 5/2, 1/4, 2] and [5/4, 5/2, 1/3, 2].
How to use maple to fulfill this task?
Upvotes: 2
Views: 161
Reputation: 7271
L := [[5/4,5/2,1/3,2] , [1,5/2,3/5,1.5],
[5/4,5/4,3/5,1.5], [5/4,5/2,1/4,2]]:
sort(L,key=evalf);
[[1, 5/2, 3/5, 1.5], [5/4, 5/4, 3/5, 1.5],
[5/4, 5/2, 1/4, 2], [5/4, 5/2, 1/3, 2]]
# alternatively
L[sort(evalf(L),output=permutation)];
[[1, 5/2, 3/5, 1.5], [5/4, 5/4, 3/5, 1.5],
[5/4, 5/2, 1/4, 2], [5/4, 5/2, 1/3, 2]]
sort(L); # like set-ordering
[[1, 5/2, 3/5, 1.5], [5/4, 5/2, 1/3, 2],
[5/4, 5/2, 1/4, 2], [5/4, 5/4, 3/5, 1.5]]
Upvotes: 1