# Place symbols from small to big

I am wondering how to compare the different values of ω I derived in this code, and place them in order as follows. (use Print or something?)

I would like to have ω placed in order in the output, instead of the values of ω.

$$\omega_{11} < \omega_{22} < \omega_2 < \omega_1$$

I would like to have ω placed in order in the output, instead of the values of ω.

Remove["Global*"]

x1[t_] = A1 E^(I ω t);
x2[t_] = A2 E^(I ω t);

eqn1 = m x1''[t] + 2 k x1[t] - k x2[t] == 0 /. t -> 0;
eqn2 = m x2''[t] - k x1[t] + k x2[t] == 0 /. t -> 0;

org = k/m SparseArray[{{1, 1}, {1, 2}, {2, 1}, {2, 2}} -> {2, -1, -1, 1}];

eigena = Sqrt[org // Eigenvalues];

"The charactersitic frequencies are: "
Column[Subscript[ω, #] & /@ Range@2 == eigena // Thread,
Spacings -> 2]
For[i = 1, i < 3, i++, Subscript[ω, i] = eigena[[i]]]

"When the upper mass m1 is fixed, x1[t]=0, for all t values"

eqn11 = x2''[t] == -k/m x2[t];

"Just by observation, the frequency is:"

Subscript[ω, 11] == Sqrt[k/m]
Subscript[ω, 11] = Sqrt[k/m];

"When the upper mass m2 is fixed, x2[t]=0, for all t values"

eqn22 = x1''[t] == -2 k/m x1[t];

"Just by observation, the frequency is:"

Subscript[ω, 22] == Sqrt[2 k/m]
Subscript[ω, 22] = Sqrt[2 k/m];

Sort[{Subscript[ω, 1], Subscript[ω, 2], Subscript[ω, 11], Subscript[ω, 22]}
] /. k -> 1 /. m -> 1

-
@Kuba Is the question clear after I revised it? – Lawerance May 25 '14 at 21:01
Yes it is but is the rest of the code relevant, isn't it only about the last line? – Kuba May 25 '14 at 21:11
@Kuba Yes, it's about the last line. But I also feel that my code doesn't look nice, so I am wondering if someone may help me polish it. – Lawerance May 25 '14 at 21:23
@Kuba Do you know how to make ω appear among the <, instead of the numerical values? – Lawerance May 25 '14 at 21:26
@Kuba I know how to sort the numerical values in order, but how to make a connection to their symbols ω, and place them in order? This is my confusion. – Lawerance May 25 '14 at 21:31

This is ugly ;), but I think it is what you are after.

Composition[
Row[#[[;; , 1]], " < "] &,
SortBy[#, N[#[[2]]] &] &,
ReleaseHold,
MapAt[HoldForm, #, {1, ;; , 1}] &,
# /. s_Subscript :> RuleCondition@{HoldForm[s], s /. k -> 1 /. m -> 1} &
]@Hold[{Subscript[ω, 1], Subscript[ω, 2], Subscript[ω, 11], Subscript[ω, 22]}]


-
Yes, that's what I'm looking for. Indeed, it is quite complicated. Do you know is there other simpler command to accomplish this? – Lawerance May 25 '14 at 21:33
@Lawerance generally you can do something like: {"a", "b", "c", "d"}[[Ordering[{1, 3, 2, 0}]]] but I've assumed you want all that to do programmatically and you have not written those names as strings for example. That's why it is so long. Feel free to hold on with an accept, maybe someone will provide better answer. – Kuba May 25 '14 at 21:37
Yes, you are exactly right. That's why I think my code does not look nice. – Lawerance May 25 '14 at 21:43

I think this does what you want:

Less @@ SortBy[Defer[Subscript[ω, #]] & /@ {1, 2, 11, 22}, N @@ # &]


-
This is so clean. +1 – RunnyKine Aug 15 '14 at 17:48

Here is a function to show the order of a list of expressions. By using Less as in the question, I'm assuming the expressions are unequal.

ClearAll[showOrder];
SetAttributes[showOrder, HoldAll];
showOrder[{e__}] := Defer /@ Hold[e][[Ordering[{e}, All, Less]]] /. Hold -> Less


OP's example:

Block[{k = 1, m = 1},
showOrder[{Subscript[ω, 1], Subscript[ω, 2], Subscript[ω, 11], Subscript[ω, 22]}]
]


Another example:

showOrder[{1, 4, 3, 2}]
(* 1 < 2 < 3 < 4 *)
`
-