Solving Linear System with Eigenvalues in Matlab

In summary, the conversation discusses sorting eigenvalues and eigenvectors in a linear system using Matlab. The user is generating a new matrix each time and using the eig function to find the eigenvalues. They are experiencing issues with the plot and are seeking advice on how to properly sort the eigenvalues and align them with their corresponding eigenvectors. Suggestions are made to use the sort and diag functions to achieve this.
  • #1
member 428835
Hi PF!

I am looping through a linear system and each time I do I generate a new matrix, call this matrix ##A##. When finding the eigenvalues of ##A## in Matlab is use
Code:
[a,sigma2M] = eig(A);% a eigenvector and sigma2M matrix of eigenvalues
sigma2(:,ii) = sum(sigma2M);% create matrix with rows of eigenvalues for the iith system
where the ii is the for loop. The plot I get looks bad and you can see how some eigenvalues get mixed up (vertical axis are eigenvalues). Any ideas? I'd really appreciate it!
eigenvalues.png
 
Physics news on Phys.org
  • #2
Sort the eigenvalues?
 
  • #3
Orodruin said:
Sort the eigenvalues?
Doesn't it automatically do this for me? Is there a way to have this automated?
 
  • #4
joshmccraney said:
Doesn't it automatically do this for me? Is there a way to have this automated?
If it did you would not get the result you are getting. Use the sort function.

I also recommend against using sum to get the eigenvalues out. The matrix contains the eigenvalues on the diagonal so use diag instead. For a square matrix it will give you a vector containing the diagonal elements.
 
  • Like
Likes member 428835
  • #5
Orodruin said:
If it did you would not get the result you are getting. Use the sort function.

I also recommend against using sum to get the eigenvalues out. The matrix contains the eigenvalues on the diagonal so use diag instead. For a square matrix it will give you a vector containing the diagonal elements.
Good call on the diag function. I'd like the eigenvalues to remain paired with their corresponding eigenvectors. When I use sort on the eigenvalues, that only change their positions? Do you know of a way to have the eigenvectors align with the eigenvalues?
 
  • #6
If you have the sort function output two return values, i.e.,
Code:
[B,I] = sort(A);
then B will contain the sorted list of eigenvalues and I will be a list of indices which is the order of the original indices. You can sort the eigenvectors by using the array I accordingly as an argument of the matrix containing the eigenvectors.
 
  • Like
Likes member 428835
  • #7
Thanks got it!
 

1. How do I solve a linear system using eigenvalues in Matlab?

To solve a linear system using eigenvalues in Matlab, you can use the eig function to find the eigenvalues and eigenvectors of the coefficient matrix. Then, you can use these eigenvalues and eigenvectors to create a diagonal matrix and solve for the unknown variables in the system.

2. Can I use Matlab to solve a linear system with complex eigenvalues?

Yes, Matlab can handle complex eigenvalues when solving a linear system. The eig function will return complex eigenvalues and eigenvectors if they exist in the system.

3. Is it necessary to find the eigenvalues and eigenvectors when solving a linear system in Matlab?

Yes, finding the eigenvalues and eigenvectors is a crucial step in solving a linear system using eigenvalues in Matlab. These values are used to create a diagonal matrix which is then used to solve for the unknown variables in the system.

4. What are the advantages of using eigenvalues to solve a linear system in Matlab?

Using eigenvalues to solve a linear system in Matlab can provide a more efficient and accurate solution compared to other methods. It also allows for handling complex systems and can be easily implemented in Matlab.

5. Are there any limitations to using eigenvalues in Matlab to solve linear systems?

One limitation of using eigenvalues in Matlab to solve linear systems is that it can only be applied to square systems with the same number of equations and variables. It also assumes that the system is consistent, meaning it has a unique solution.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
859
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Calculus and Beyond Homework Help
Replies
2
Views
521
  • Engineering and Comp Sci Homework Help
Replies
18
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
6K
  • Calculus and Beyond Homework Help
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Replies
4
Views
1K
Back
Top