我試圖編寫一個將矩陣分解爲SVD格式的matlab代碼。SVD Matlab的實現
「理論」:
要獲得U,我發現AA的特徵向量」,並獲得V,我發現A'A的特徵向量。最後,Sigma是與A相同維數的矩陣,特徵值在對角線上的根在有序序列中。
但是,它似乎沒有正常工作。
A=[2 4 1 3; 0 0 2 1];
% Get U, V
[aatVecs, aatVals] = eig(A*A');
[~, aatPermutation] = sort(sum(aatVals), 'descend');
U = aatVecs(:, aatPermutation);
[ataVecs, ataVals] = eig(A'*A);
[~, ataPermutation] = sort(sum(ataVals), 'descend');
V = ataVecs(:, ataPermutation);
% Get Sigma
singularValues = sum(aatVals(:, aatPermutation)).^0.5;
sigma=zeros(size(A));
for i=1:nnz(singularValues)
sigma(i, i) = singularValues(i);
end
A
U*sigma*V'
U *西格瑪* V」似乎爲-1的因子返回:
ans =
-2.0000 -4.0000 -1.0000 -3.0000
0.0000 0.0000 -2.0000 -1.0000
什麼代碼或‘理論’,導致它的錯誤呢?
我在去年5月寫了這篇文章:[手工計算SVD](http://math.stackexchange.com/a/1805239/339790)。 –