Error in svd in r2018a
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
N/A
am 17 Jul. 2022
Kommentiert: Christine Tobler
am 5 Aug. 2022
[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 Kommentar
Walter Roberson
am 17 Jul. 2022
The problem would continue if eps(A) > 1e-14 which would be the case if abs(A) > 100 or so
Akzeptierte Antwort
Bruno Luong
am 17 Jul. 2022
Bearbeitet: Bruno Luong
am 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 Kommentar
Christine Tobler
am 5 Aug. 2022
Weitere Antworten (1)
Steven Lord
am 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.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!