cancel
Showing results for
Search instead for
Did you mean:
cancel
Showing results for
Search instead for
Did you mean:

Highlighted
Newbie

## Eigenvalues out of order

I have a problem with the eigenvals() function. USALLY the results are sorted from largest to smallest, but occasionally they will be out of order. I have found the following simple matrix that demonstrates this:

[A] = 1.0053 1.0053 1.0053

1.0053 2.0001 2.0001

1.0053 2.0001 3.4365

eigenvals(A) = {5.301 0.337 0.803}

This can be a tremendous problem if, for example, I have a 100x100 matrix and I only need the first 3 eigenvalues and their associated eigenvectors.

See attached mathcad sheet with demo and illustration of what I go through to sort the values and vectors properly. Surely there must be a better way!

Tags (3)
25 REPLIES 25

## Re: Eigenvalues out of order

No problem for any n x n out of "as big as can the matrix be" .

Mathcad 11 takes a size up to 4096 x 4096.

Will that be enough for your project?

jmG

## Re: Eigenvalues out of order

What???

I don't understand your answer. Perhaps you didn't understand my question.

I'm complaining that the returned eigenvalues are not sorted in order, and I would like to know if this is a bug. The eigenvalues are always sorted when I use functions in other languages or applications. I find it hard to believe that the Mathcad behavior is intentional.

Your response seems only to demonstrate a method of extracting a submatrix, and what large matrices it works with, but I don't care about that.

## Re: Eigenvalues out of order

 DARYL BOGGS wrote:I'm complaining that the returned eigenvalues are not sorted in order, and I would like to know if this is a bug. The eigenvalues are always sorted when I use functions in other languages or applications. I find it hard to believe that the Mathcad behavior is intentional.

I'm not sure that all maths applications return sorted eigenvalues - I've got a feeling that I've seen something about Maple not sorting and I don't know that there is a 'standard' as such (I've seen a few requests for reversing the sort order in Matlab as well). I believe that GNU has functions that allow the user to specify the sort order, but I haven't checked.

However, it is deliberate and the subject has been discussed before - see here for example.

You could get round your sort problem by cheating and stacking max(eigenvals)-eigenvals before sorting and then carrying out the same operation. See attached worksheet.

## Re: Eigenvalues out of order

In version 15 they are in order. They do fix some things, some of the time 🙂

If you really need only the first 3 out of 100 eigenvectors the best thing is not to get all the eignvectors in the first place though. Get the eigenvalues, sort them, and then get the first 3 eignevectors using the eigenvec function. Or you could use the syntax in the attached worksheet to get all of them.

## Re: Eigenvalues out of order

 DARYL BOGGS wrote:What???I don't understand your answer. Perhaps you didn't understand my question.I'm complaining that the returned eigenvalues are not sorted in order, and I would like to know if this is a bug. The eigenvalues are always sorted when I use functions in other languages or applications. I find it hard to believe that the Mathcad behavior is intentional.Your response seems only to demonstrate a method of extracting a submatrix, and what large matrices it works with, but I don't care about that.

Eigenvalues arrive as they they are found. Easy to extract the three ones you want out of a vector of 1100 elements. If you think that the three such roots represent something about your project, just do. If Mathcad does not immediately do what you ask for, you can be sure that's because it has nothing to do with the maths of it ... and you won't even need the extractor [that you can recycle].

"The eigenvalues of a matrix m are the values lfor which one can find non­zero vectors xi such that m*xi = l*xi. The eigenvectors are the vectors xi.
Finding the eigenvalues of an n x n matrix in principle involves solving an nth degree polynomial equation. For n>5, therefore, the results cannot in general be expressed purely in terms of explicit radicals. Root objects can nevertheless always be used, although except for fairly sparse or otherwise simple matrices the expressions obtained are often unmanageably complex." [Mathematica].

jmG

## Re: Eigenvalues out of order

I was wondering what the three highest eigenvalues could represent wrt an "n x n" system. No abstract, not even a hint ! So, I will leave it there unless more help is specified c/w a work sheet and the issue of the project. Hopefully it has nothing to do with attempting to approximate something unknown.

Cheers Stuart, Richard

## Re: Eigenvalues out of order

 jean Giraud wrote:I was wondering what the three highest eigenvalues could represent wrt an "n x n" system.

For one example, look in the DAEP under principle component analysis.

## Re: Eigenvalues out of order

>For one example, look in the DAEP under principle component analysis.< [Richard]

__________________

Thanks Richard, I have recollection of the work you did. Mathematica does not sort eigenvalues.

## Re: Eigenvalues out of order

Ian Ward has a great solution to this problem in his post DynamAssist to the old collab.

I have borrowed it and found it very useful.