Solving Linear System with Eigenvalues in Matlab

Click For Summary

Discussion Overview

The discussion revolves around solving a linear system in Matlab, specifically focusing on the computation and sorting of eigenvalues and eigenvectors. Participants explore issues related to the visualization of eigenvalues and seek methods to align eigenvalues with their corresponding eigenvectors.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant describes a process for generating a matrix ##A## and finding its eigenvalues using Matlab, but expresses concern over the quality of the resulting plot.
  • Another participant suggests sorting the eigenvalues to improve the plot.
  • A participant questions whether eigenvalues are automatically sorted by Matlab and seeks clarification on automating this process.
  • It is noted that the eigenvalues are on the diagonal of the matrix returned by the eig function, and using the diag function is recommended over using sum to extract them.
  • A participant inquires about maintaining the pairing of eigenvalues with their corresponding eigenvectors after sorting.
  • Another participant explains how to use the sort function to obtain both sorted eigenvalues and the indices for sorting the eigenvectors accordingly.

Areas of Agreement / Disagreement

Participants generally agree on the need to sort eigenvalues and the use of the diag function to extract them, but there is no consensus on the automatic sorting behavior of Matlab or the best method to align eigenvectors with sorted eigenvalues.

Contextual Notes

Participants discuss the limitations of the current approach, including potential confusion regarding the sorting of eigenvalues and the extraction of eigenvalues from the eig function output.

Who May Find This Useful

This discussion may be useful for individuals working with linear systems in Matlab, particularly those interested in eigenvalue problems and data visualization techniques.

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
Sort the eigenvalues?
 
Orodruin said:
Sort the eigenvalues?
Doesn't it automatically do this for me? Is there a way to have this automated?
 
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   Reactions: member 428835
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?
 
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   Reactions: member 428835
Thanks got it!
 

Similar threads

  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
11
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
6K