matlab svd 和 eig 的區別

 

轉自:

https://my.oschina.net/duluo180/blog/736587

 

總得來說,SVD eig 得到的特徵值/奇異值是一樣的,eig排列是降序,svd排列是升序;

SVD的右奇異向量是A'*A的特徵向量

SVD的左奇異向量是A*A'的特徵向量

另外,SVD可以用於非方陣的分解,而eig只能用於方陣的分解

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
% A'*A 的特徵向量 是A的右奇異向量
[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
% A*A' 的特徵向量 是A的左奇異向量
[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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章