2014-09-30 32 views

回答

1

一种方法是eigs:

[V,D] = eigs(A,size(A,1)-1) 

第二种方式是进行排序:

if ~issorted(diag(D)) 
    [V,D] = eig(A); 
    [D,I] = sort(diag(D)); 
    V = V(:, I); 
end 
0
p=3; %'as a example say we want the eigenvectors for the 3 largest eigenvalues' 

X=rand(4); %'take whatever matrix 4x4 for the example' 

[V, D] = eig(X); 

for ind=1:length(D) 
    d(ind)=abs(D(ind,ind)); 
end 

[B,IX] = sort(d,'descend'); 

Y = V(:,IX(1:p)); 

Y的列包含从左到右按降序排列的特征向量对应的特征向量。 请注意,我使用abs()函数来测量特征值的“大小”。请注意,也许你更喜欢使用其他功能。

+0

为什么for循环使用,而不仅仅是' [〜,IX] = sort(abs(diag(D)))或者[V,D] = eig(X,'vector'); [〜,IX] = sort(abs(D))'? – Dan 2014-09-30 06:00:09

相关问题