       • To: mathgroup at smc.vnet.net
• Subject: [mg90876] Re: question about sorting lists
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Sun, 27 Jul 2008 02:32:27 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <g6emrs\$cmj\$1@smc.vnet.net>

Tatyana Polenova wrote:

> I have the following numerical list:
>
> {{{x1, x2, x3}, {{x11, x12, x13}, {x21, x22, x23}, {x31, x32, x33}}}
>
> where x1, x2, and x3 are some eigenvalues, and {x11, x12, x13}, {x21,
> x22, x23}, and {x31, x32, x33} are their corresponding eigenvectors.
>
> I need to sort the list so that the eigenvalues are arranged in the
> order of decreasing the absolute value of the difference between any
> of the two eigenvalues. (and that the eigenvectors still correspond to
> the original eigenvalues).
>
> What would be the correct syntax for this operation in Mathematica 5.2?

First the easy part of your question. Say we want to sort the
eigenvalues in increasing order and keep their respective eigenvector in
order. One possible way of doing that is as follows:

eigsys = Eigensystem[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}] // N
{eigsys[[1, #]], eigsys[[2, #]]} &[Ordering[eigsys[]]]

{{16.1168, -1.11684, 0.}, {{0.283349, 0.641675, 1.},
{-1.28335, -0.141675, 1.},
{1., -2., 1.}}}

{{-1.11684, 0., 16.1168}, {{-1.28335, -0.141675, 1.},
{1., -2., 1.},
{0.283349, 0.641675, 1.}}}

(Note that functions such as Sort, Ordering, etc., all have a second or
third optional argument that specifies the sort function -- relation --
to use.)

specifications, your criterion is not strong enough to define an order
relation (among other things, it is not antisymmetric).

For instance, say we have the eigenvalues {-1, 0, 1}. How would you
ordered them? You might say (-1, 1, 0) for the distances among adjacent
pairs are 2 (Abs[(-1) - 1]) and 1 (Abs[1 - 0]). Now the triple (1, -1,
0) also matches the same "order". So which one to choose?

Regards,
-- Jean-Marc

• Prev by Date: Re: Re: Function Programming Problems
• Next by Date: Re: Re: Text search within a documentation page?