Matlab eigenvalues and eigenvectors--arranging eigenvalues in order from large to small

Source: Internet
Author: User
Tags sort

In the job need to find the eigenvalues and eigenvectors of a matrix, of course, the students will use the MATLAB built-in functions [V, D] = Eig (A), so that the diagonal matrix D is a small-to-large arrangement of the characteristics of the value. Some students want to be able to separate this diagonal element into a row vector or column vector, but also hope that the characteristics of the value from large to small arrangement, in order to achieve this goal, we have used a variety of methods. In fact, MATLAB built-in functions have diag () can be a diagonal matrix into a vector, you can also convert a vector into a diagonal matrix. After the conversion of the vector in reverse order, I see a classmate obstinately wrote a bubble sort to complete this work, your data structure the teacher must be very gratified. But in MATLAB do not have to start from scratch, directly call the sort () function on the line ~ But here there are more simple methods, Wrev () function can be a vector in reverse order, FLIPLR () function can be a matrix left and right mirror symmetry, so if you want to get from large to small arrangement of eigenvalues, As long as this is OK:

% get eigenvalues from large to small arranged
[V, D] = Eig (A);
Lambda = Wrev (diag (D));
v = FLIPLR (v);

The eigenvalues and eigenvectors are all lined up.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.