Eig doesn't converge - can you explain why?

10 views (last 30 days)
Hi,
I have been having a problem with the eigenvalue function. I have two 240x240 matrices (which I have attached with this post) that I add together, and then get matrices of eigenvalues and eigenvectors. I have many such matrices like the ones that I posted that are added together and such during the program, but this combination does not work for some reason. It always works with the eigenvalues, so it seems like the eigenvectors are causing the problem. Any clues as to why so? The line of code that I have been using is:
[a,b] = eig(hh(1:240,1:240)+ pot(1:240,1:240));
The reason that I specified the range of indices is that if I use either 1:239 or 2:240 on both "hh" and "pot" at the same time, the eig function doesn't have a problem anymore. Anyway, thanks for any help you can give.
  3 Comments
Benjamin Pound
Benjamin Pound on 24 Feb 2015
When I try to run the line of code in my original post (or your code, it makes no difference), I get an error that says "Error using eig. EIG did not converge." So I wonder what is different when you run it. What version of MATLAB are you using? I am using 2014a.
Florian Roemer
Florian Roemer on 12 Jul 2017
I encountered a similar problem in Matlab R2014a. For very particular matrices I have
[V,E] = eig(A)
give me the error "Error using eig: eig did not converge", while on the very same matrix
E = eig(A)
works just fine. So I can get the eigenvalues but not the eigenvectors. This problem seems to be fixed in newer versions of Matlab, at least it worked on another machine where I have R2017a installed.
For R2014a, funnily it works if I switch to a generalized eigenvalue problem eig(A,B), which for B=I should give exactly the same result. But I guess it uses a slightly modified algorithm. Therefore, I'm using the following workaround right now:
try
[V,E] = eig(A);
catch
[V,E] = eig(A,eye(size(A)));
end
which works fine in R2014a.
The matrix where I encountered the problem was symmetric but not positive definite, i.e., it had positive and negative eigenvalues and some close to zero (1e-6 where the largest was around 2).

Sign in to comment.

Accepted Answer

Alexandre Djerbetian
Alexandre Djerbetian on 24 Feb 2015
Edited: Alexandre Djerbetian on 24 Feb 2015
Hi Benjamin,
I encountered the same problem. I am also interested in knowing why this problem occurs. If you look for a workaround, here is one which worked for me: I just 'smooth' my matrix. If A is the matrix you want to use eig on and which is causing problem, I did:
% First we compute the squared Frobenius norm of our matrix
nA = sum(sum(A.^2));
% Then we make this norm be meaningful for element wise comparison
nA = nA / numel(A);
% Finally, we smooth our matrix
As = A;
As( As.^2 < 1e-10*nA ) = 0;
Just in case you want to check that the results are indeed what you want, I checked the validity of the results:
% We check that the result is correct
ev = eig(A);
[eVs,evs] = eig(As);
fprintf('Error of smoothing: %g%%\n',100*norm(ev-evs)/norm(ev));
Since our new matrix is very close to the original one, and since the eigen values are continuous functions of our matrix elements, the result of eig on this new smoothed matrix should be very close to the original. You can also smooth your matrix more or less by adjusting the 1e-10.
I attached my example. I get an error of 5e-9 and eig works.
I hope I helped. Good luck !
  1 Comment
Benjamin Pound
Benjamin Pound on 25 Feb 2015
As an alternative, I have found that using the vpa() command does also give results - at least, it doesn't crash the program. However, it takes a very long time to evaluate my little matrix (something like 5 minutes ...), and it might have other problems too. So I'm still open to other options.
As for your answer, my eigenvalues and eigenvectors can be computed from the smoothed matrix. My error is significantly higher than yours, however, at around 8.6%, but I think that it is good enough for my purpose.

Sign in to comment.

More Answers (0)

Categories

Find more on Linear Algebra in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!