Given a big square matrix and some eigenvalues, how to find the corresponding eigenvectors?
11 views (last 30 days)
Show older comments
My computer configuration: CPU: 8 cores 4.6GHz, 16GB memory.
I have a big matrix A with size(A) = (3072,3072)
I can get the eigenvalues by doing
v = eig(A)
But my computer dies if I do
[V,D] = eig(A)
I need the corresponding eigenvectors of some of the eigenvalues in v, saying I need 180 eigenvectors, and the corresponding eigenvalues are biggest among v. How to do it?
3 Comments
the cyclist
on 2 Jan 2023
@Bruno Luong, can you explain a bit more (or point to documentation) about why one would not expect
eigs(A,180)
would be expected to give less accurate eigenvectors than the first 180 eigenvectors (sorted by magnitude) of
eig(A)
?
I'm not doubting you! It's just surprising to me, and I'd like to understand that better.
Bruno Luong
on 2 Jan 2023
Edited: Bruno Luong
on 3 Jan 2023
The eigs command is based on Krylov subspace and it is quite poor and fragile numerically. This kind of warning happens all the time
A=rand(1000);
[V,D]=eig(A,'vector');
[~,is]=sort(abs(D),'descend');
Vs=V(:,is);
Ds=D(is);
[Veigs,Deigs]=eigs(A,10);
Deigs=diag(Deigs);
for k=1:size(Veigs,2)
errorD = abs((Ds(k)-Deigs(k))/Ds(k));
errorV = norm(dot(Veigs(:,k),Vs(:,k))/(norm(Veigs(:,k).*norm(Vs(:,k)))))-1;
fprintf('k=%d, errorD = %f, errorV = %f\n', k, errorD, errorV)
end
eig works just fine.
That happens more on the middle of the spectrum when the eigenvalues are dense, creating converging issue of the iterative method.
You can run my code several time, some time eigs works ùost of the time it's not.
Accepted Answer
Christine Tobler
on 3 Jan 2023
Edited: Christine Tobler
on 3 Jan 2023
I wouldn't expect a 3072-by-3072 matrix to be a problem on the machine you describe. Could you try to run the following on your machine?
A = randn(3072, 3072);
% A = A + A'; % if your original matrix is symmetric, please also symmetrize here
[U, D] = eig(A);
I'd like to find out if it's any matrix of this size that's causing an issue, or just your particular one.
3 Comments
Walter Roberson
on 4 Jan 2023
That WHEA_UNCORRECTABLE_ERROR error message appears to be associated with overclocking to the point where your system becomes unstable.
By extension it could also probably happen if your system is getting overheated even without overclocking.
If this is a desktop or tower machine, be sure to clean out any dust that may have accumulated inside of it.
More Answers (2)
the cyclist
on 2 Jan 2023
You could try to use eigs instead of eig. It allows you to get the largest N eigenvalues and the corresponding eigenvectors.
0 Comments
John D'Errico
on 2 Jan 2023
Edited: John D'Errico
on 2 Jan 2023
A = magic(8)
format long g
[V,D] = eig(A); d = diag(D)
Now we wish to solve for the eigenvector, corresponding to one of the eigenvalues, as if we did not know the eigenvector already. In this case, we know it, but we need to check how well we did.
eigenvec = @(A,e,n) [A - e*eye(n);[1,zeros(1,n-1)]]\[zeros(n,1);1];
All I did there was to enforce that the first element of the eigenvector is 1. This arbitrarily scales the eigenvector. But except for rare occasions, when the first element of the corresponding eigenvector would have been exactly zero, this will make the system non-singular.
n = size(A,1);
V1 = eigenvec(A,d(1),n);V1 = V1/norm(V1);
[V(:,1),V1]
In some cases, the two vectors will differ by a factor of -1, but that should be all.
Honestly what I'm not sure I know is why your computer is failing to compute the eigenvectors. 3024 is a pretty small system these days. My computer did not even make a small hiccup when I try that.
0 Comments
See Also
Categories
Find more on Linear Algebra 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!