# Given a big square matrix and some eigenvalues, how to find the corresponding eigenvectors?

12 visualizzazioni (ultimi 30 giorni)
yi yang il 2 Gen 2023
Commentato: yi yang il 4 Gen 2023
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 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
the cyclist il 2 Gen 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 il 2 Gen 2023
Modificato: Bruno Luong il 3 Gen 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);
Warning: 7 of the 10 requested eigenvalues converged. Eigenvalues that did not converge are NaN.
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
k=1, errorD = 0.000000, errorV = 0.000000 k=2, errorD = 0.000000, errorV = 0.000000 k=3, errorD = 0.000000, errorV = 0.000000 k=4, errorD = NaN, errorV = 0.000000 k=5, errorD = NaN, errorV = 0.000000 k=6, errorD = 1.229746, errorV = -0.974433 k=7, errorD = 1.940090, errorV = -0.971715 k=8, errorD = 1.995754, errorV = -0.972432 k=9, errorD = 1.965161, errorV = -0.930798 k=10, errorD = NaN, errorV = -0.973482
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.

Accedi per commentare.

### Risposta accettata

Christine Tobler il 3 Gen 2023
Modificato: Christine Tobler il 3 Gen 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 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Walter Roberson il 4 Gen 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.
yi yang il 4 Gen 2023
Confirmed. It is my memory problem.
My memory was running at 3200MHz, which is recommended by the manufacture. bluescreen, freezing
Now it is running at 2400MHz, which is my system default. No bluescreen, no freezing.
Thanks guys for helping

Accedi per commentare.

### Più risposte (2)

the cyclist il 2 Gen 2023
You could try to use eigs instead of eig. It allows you to get the largest N eigenvalues and the corresponding eigenvectors.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

John D'Errico il 2 Gen 2023
Modificato: John D'Errico il 2 Gen 2023
A = magic(8)
A = 8×8
64 2 3 61 60 6 7 57 9 55 54 12 13 51 50 16 17 47 46 20 21 43 42 24 40 26 27 37 36 30 31 33 32 34 35 29 28 38 39 25 41 23 22 44 45 19 18 48 49 15 14 52 53 11 10 56 8 58 59 5 4 62 63 1
format long g
[V,D] = eig(A); d = diag(D)
d =
260 + 0i 51.8459255872628 + 0i -51.8459255872629 + 0i 3.30788760574535e-15 + 1.120272933028e-14i 3.30788760574535e-15 - 1.120272933028e-14i 6.18932227044616e-15 + 0i 9.94987338090162e-16 + 0i -4.24981561804611e-15 + 0i
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]
ans = 8×2
0.353553390593274 0.353553390593274 0.353553390593273 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274 0.353553390593274
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 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Linear Algebra in Help Center e File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by