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

5 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

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.

### More Answers (2)

the cyclist
on 2 Jan 2023

##### 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

### Community Treasure Hunt

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

Start Hunting!