Error in svd in r2018a
1 次查看(过去 30 天)
显示 更早的评论
[U,s,V] = svd(A + 1e-14*randn(size(A)));
but I still getting the same error every now and then. How do you recommend getting around this error without increasing the size of the perturbation? Could I increase the number of iterations to test convergence, if so how? Or something else?
1 个评论
Walter Roberson
2022-7-17
The problem would continue if eps(A) > 1e-14 which would be the case if abs(A) > 100 or so
采纳的回答
Bruno Luong
2022-7-17
编辑:Bruno Luong
2022-7-17
As Walter has pointed out, the workwaround given by TMW might be still flawed because it ignores the scale of A.
A better solution would be
A = randi(100,4,6)
[U,s,V] = svd(A + norm(A)*1e-14*randn(size(A)))
Or might be this cumbersome code that uses EIG (hopefully not buggy in your version) instead of SVD.
[m,n] = size(A);
AAc = A*A'; [U,s2u] = eig(1/2*(AAc+AAc'));
AcA = A'*A; [V,s2v] = eig(1/2*(AcA+AcA'));
[~, isu] = sort(sqrt(max(diag(s2u),0)),'descend');
[s, isv] = sort(sqrt(max(diag(s2v),0)),'descend');
U = U(:,isu);
S = diag(s);
if n < m
S(m,1) = 0;
isv = isv(1:n);
else
S = S(1:m,:);
end
V = V(:,isv);
U
S
V % Note the two last columns are arbitrary provided they span the same subspace and are orthogonal
1 个评论
Christine Tobler
2022-8-5
更多回答(1 个)
Steven Lord
2022-7-17
Are you using Update 3 of release R2018a or a later Update, or are you using release R2018a (no Update) or Updates 1 or 2?
If you have not installed Update 3 or a later Update, please do.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!