Sort by Frequency



On 12/3/07, Stefan Joeres <not_me at gmx.de> wrote:

> Using trigreduce(y) leads to
> terms of cos(w1), cos(w2), cos(2*w1+w2) ... and so on.
> I'd like to sort these terms according to those cos() coefficients.

The sort function sorts all kinds of expressions.

sort ([cos(w1 + w2), cos(w2^2), cos(w1), cos(2*w1 + w2), cos(w2)]);
 => [cos(w1), cos(w2), cos(w2 + w1), cos(w2 + 2 w1), cos(w2^2)]

Maxima has its own idea about how to order non-atomic expressions.
If you don't like that order, you can tell sort to use a specific
comparison function.
? sort
says more about that.

HTH

Robert Dodier