Optimizing calculation of eigenvectors and eigenvalues
Show older comments
I have a quadratic matrix A with a size of about 2000x2000. I want to calculate its eigenvectors and eigenvalues. The eigenvalues must be in a vector (not a diagonal matrix as usual). I use the following code:
eigenvals = abs(real(eig(A)));
[eigenvecs, ~] = eig(A);
eigenvecs = real(eigenvecs);
The problem is that it takes a lot of time (about 15 seconds) and I need to repeat this process a lot of times in a loop. So I tried to optimize it and changed it to this:
[eigenvecs, eigenvals]=eig(A);
eigenvecs=real(eigenvecs);
eigenvals=abs(real(diag(eigenvals)));
This runs about 5 seconds faster. The calculated eigenvectors are the same for both code snippets, however the eigenvalues are not and differ a bit. How could I further optimize the code in a way that it delivers equivalent results to the first code snippet?
Thank you very much in advance!
Accepted Answer
More Answers (0)
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!