Should I use EIG or SVD to compute the eigenvalues of a symmetric matrix?
Show older comments
I saw ths question posed as an answer to another question. So I'll pose the question myself, then post my own thoughts as my answer. But feel free to add your own ideas.
The question there was given a matrix like
A = [6 2 1;2 5 2;1 2 3]
we see that both eig and svd can be used to compute the eigenvalues and eigenvectors. Thus:
[W,D] = eig(A)
[U,S,V] = svd(A)
And the two seem to return subtly different results. Is one better? Is one more correct? Is one faster, more efficient?
Answers (2)
2 Comments
Why is only SPD being considered here? Isn't it true that theoretically U = W for any symmetric matrix?
Note that the original thread that motivated this Question was discussing eigenvectors, not eigenvalues, though I realize now that this Question is about eigenvalues, though this answer is also discussing eigenvectors.
It's a tricky question - there's an advantage in having a symmetric form U*D*U' from calling EIG, but there's also an advantage in SVD guaranteeing all nonnegative singular values, while EIG will return negative eigenvalues sometimes.
I think this question often comes up for the case where A is ill-conditioned SPD, where EIG may return some negative eigenvalues on the round-off level. Using the SVD there seems helpful, but the assumption of U and V being largely the same isn't true there anymore:
rng default;
A = randn(7, 10); A = A'*A;
[U, D] = eig(A);
norm(A - U*D*U')
norm(U'*U - eye(10))
[U, S, V] = svd(A);
norm(A - U*S*V')
norm(U'*V - eye(10))
The large error at the end isn't down to scaling of the columns of U and V, instead those columns are in a different order in U and in V. Basically the last three columns of U and V each are a basis of the null-space of A, but they don't have to be the same basis.
No matter if EIG or SVD is used, one usually has to add some separate code to deal with round-off level eigenvalues in some way (setting them all to exact zero for example).
Bruno Luong
on 14 Jul 2022
Edited: Bruno Luong
on 14 Jul 2022
I always use EIG on SDP matrix, for the "same" reason that I use
A\b
preferable to
(A'*A) \ (A'*b)
to solve least square solution of A*x = b for tall A.
I simply have intuition that SVD works on A'*A or A*A' behind the scene.
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!