2

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?

panmd
  • 21
  • 2

1 Answers1

1
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]]
acer
  • 6,671
  • 15
  • 15