Error in svd in r2018a
4 views (last 30 days)
Show older comments
[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 Comment
Walter Roberson
on 17 Jul 2022
The problem would continue if eps(A) > 1e-14 which would be the case if abs(A) > 100 or so
Accepted Answer
Bruno Luong
on 17 Jul 2022
Edited: Bruno Luong
on 17 Jul 2022
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 Comment
Christine Tobler
on 5 Aug 2022
More Answers (1)
Steven Lord
on 17 Jul 2022
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.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!