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.

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值