您的位置:首页 > 编程语言 > MATLAB

matlab svd 和 eig 的区别

2016-08-23 00:00 232 查看
Note that eigenvectors are not unique. Multiplying by any constant, including
-1
(which simply changes the sign), gives another valid eigenvector. This is clear given the definition of an eigenvector:

A·v = λ·v

MATLAB chooses to normalize the eigenvectors to have a norm of 1.0, the sign is arbitrary:

For
eig(A)
, the eigenvectors are scaled so that the norm of each is 1.0. For
eig(A,B)
,
eig(A,'nobalance')
, and
eig(A,B,flag)
, the eigenvectors are not normalized

Now as you know, SVD and eigendecomposition are related. Below is some code to test this fact. Note that
svd
and
eig
return results in different order (one sorted high to low, the other in reverse):

% some random matrix
A = rand(5);

% singular value decomposition
[U,S,V] = svd(A);

% eigenvectors of A'*A are the same as the right-singular vectors
[V2,D2] = eig(A'*A);
[D2,ord] = sort(diag(D2), 'descend');
S2 = diag(sqrt(D2));
V2 = V2(:,ord);

% eigenvectors of A*A' are the same as the left-singular vectors
[U2,D2] = eig(A*A');
[D2,ord] = sort(diag(D2), 'descend');
S3 = diag(sqrt(D2));
U2 = U2(:,ord);

% check results
A
U*S*V'
U2*S2*V2'

I get very similar results (ignoring minor floating-point errors):

>> norm(A - U*S*V')
ans =
7.5771e-16
>> norm(A - U2*S2*V2')
ans =
3.2841e-14

EDIT:

To get consistent results, one usually adopts a convention of requiring that the first element in each eigenvector be of a certain sign. That way if you get an eigenvector that does not follow this rule, you multiply it by
-1
to flip the sign...

You can reconstruct A from its eigenvectors only if A is normal (A'*A==A*A'). You can reconstruct A from its singular vectors for any matrix A.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  matlab svd eig