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

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

1-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!

31 REPLIES 31
1-Newbie
(To:dBoggs)

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

1-Newbie
(To:jeanGiraud)

What???

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.

23-Emerald II
(To:dBoggs)
 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.

1-Newbie
(To:StuartBruff)

Thanks for the suggestion re. sort order, Stuart. I will keep it on file. But still, what a pain! The "work-around" to unsorted eigenvalues consists of five lines of Mathcad plus a small Mathcad program. This is trouble that I just don't run into with Matlab, or even several Fortran programs I have authored.

If what I heard is true that this "inconvenience" in Mathcad (OK, so its not a "bug") has been "fixed" in Mathcad 15, well so far that is the one good reason I would have for upgrading.

19-Tanzanite
(To:dBoggs)
 DARYL BOGGS wrote:The "work-around" to unsorted eigenvalues consists of five lines of Mathcad plus a small Mathcad program.

The work-around I posted requires one additional line: the defintion of a range variable.

1-Newbie
(To:dBoggs)
 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

1-Newbie
(To:jeanGiraud)

Getting the first three eigenvalues (as your program demonstrates) is not a problem. The problem is to get the corresponding eigenvectors. A method for that is what I demonstrated in the attachment to my original inquiry. Of course it can be done--I'm just saying that is a surprising inconvenience.

And no matter what other's have stated re. "pure math" issues and that there is nothing wrong, etc., well its still an inconvenience and one that doesn't exist in other applications I have experienced.

19-Tanzanite
(To:dBoggs)

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.

1-Newbie
(To:RichardJ)

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

19-Tanzanite
(To:jeanGiraud)
 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.

1-Newbie
(To:RichardJ)

>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.

1-Newbie
(To:jeanGiraud)

In my field (structural dynamics and mechanical vibrations), the eigenvalues of an nxn matrix represent the natural frequencies of vibration of an n-degree-of-freedom mechanical or structural system. The associated eigenvectors represent the mode shapes. It is very rare to need ALL of the natural frequencies--usually only the first few are of interest, in a system have thousands of degrees of freedom.

Normally, the LARGEST eigenvalue represents the LOWEST natural frequency, the second largest gives the next lowest frequency, etc. (although depending on how the matrices are set up it could be the opposite of this).

There are many similar analogies in other engineering fields. This is one reason why most engineering software will give you the first x eigenvalues and their associated eigenvectors (and you can be sure that they are sorted in order!)--however many x you ask for. The other reason is that of the many algorithms for finding eigenvalues/vectors, some of them will automatically converge on either the smallest or largest first, then "sweep out" or "purify" that answer from the matrix and reapply the search, thus finding the next smallest or largest, and on and on, however many you want to see.

There may be nothing wrong mathematically with the Mathcad algorithm, but it is certainly not a convenient result for so many applications--to the extent that I am better off using some application other than Mathcad.

1-Newbie
(To:dBoggs)

Daryl,

Did you see Richard's note above, that in Mathcad 15 the eigenvalues are now in order? That will be true for Mathcad Prime as well, when it ships.

Mona

5-Regular Member
(To:dBoggs)

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.

Daryl,

Can you send me the exact details for how you want the sorting to work for both Eigenvalues and Eigenvectors, or how it works in other programs, that is not working for you in Mathcad? I can add this to suggested features.

Thanks,

Mona

5-Regular Member
(To:mzeftel)

Mona,

You've got to get this bulletin board sorted, you are talking to Daryl by 'replying' to me. If you're getting it wrong what chance is for the rest of us?

Having all the contributions in sequence timewise would be good.

Bill

Bill,

I replied at the end of thread to make it clearer, since replying in the middle seemed to be more confusing.

I agree that having all the replies to a message in sequence order would be easier.

The Web team is working on enhancing these forums. I don't know the schedule, but some fixes have already been done.

Mona

19-Tanzanite
(To:mzeftel)
 Mona Zeftel wrote:I agree that having all the replies to a message in sequence order would be easier.

Go to "edit preferences" in your profile and change the "discussion view style" to flat. The posts will then all be in order of time. However, you then no longer get any sort of threading, so I'm not convinced it's any better. More a case of picking your poison 😞

 The Web team is working on enhancing these forums. I don't know the schedule, but some fixes have already been done.

A certainly wish they would fix the broken emoticons!

1-Newbie
(To:mzeftel)

Well I'm a little confused, since as you note Richard has indicated that the problem is now fixed, yet you're asking me for advice on how to fixt it! But thanks for asking.

The problem is simply that the eigenvalues retruned from the eigenvals() function are not in sorted order. The should be returned in the order beginning with the largest, then second largest, ...

In the example that I posted for a certain 3x3 matrix A, the values returned from eigenvals(A) were {5.301, 0.337, 0.803}. The more convenient answer, which I expect from other applications, would have been {5.301, 0.803, 0.337}. (I could demonstrate this in Matlab, or in other algorithms that I have programmed, or studied in several engineering textbooks.)

Additionally, AND THIS IS REALLY IMPORTANT, the ordering of the vectors returned by the eigenvecs(A) must also change, so that every eigenvector continues to be matched up with the corresponding eigenvalue.

Hope this helps,

Daryl

1-Newbie
(To:dBoggs)

>The should be returned in the order beginning with the largest, then second largest, ...<

_________________________

Nothing holds on that statement, mathematically. For EigenAnalysis, Mathcad shouldn't give eigenvals in sorted order if what you pretend is true, i.e: that the eigenvecs aren't in the corresponding order. Reading what you say, then the sorted option is a bug. Up to you to propose PTC the appropriate algorithm. You haven't passed any application that justifies your dissatisfaction and that could be helped. Too short, too secret does not even start collaboration.

jmG

1-Newbie
(To:jeanGiraud)

Sorry to disagree with you. I think the problem I posed is adequately described and documented.

Let me try it in words: When using most software applications, I simply ask for the first three (or whatever) eigenvalues and eigenvectors, and off I go. In Mathcad, I have to ask for all of them, then sort them, then extract the ones I want. This results in the clutter of extra steps that are not germane to the calculations that we are presenting.

I have to question whether you are ignorant of, and unreceptive to, the needs of engineers.

1-Newbie
(To:dBoggs)

What if I don't want the eigenvalues to be sorted?

Mathlab gives me always an order and I lose the trace

24-Ruby II
(To:jbrotons)

Could you provide an example of what you want?

1-Newbie

Sorry for any inconvenience. I've misplaced the question as I'm using MatLab.

24-Ruby II
(To:jbrotons)
15-Moonstone

This post was very helpful to me. I wanted to post a slight update to it, so that it works with Mathcad 15.

15-Moonstone
(To:prop_design)

I updated the files, that I posted previously, to include a lot more notes and a few more calculations.

24-Ruby V
(To:prop_design)

According rad/s vs. 1/s, Hz, etc. you might want to take a look at the unit Hza and you may be interested in this thread