Error in svd in r2018a
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
[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 Commento
Walter Roberson
il 17 Lug 2022
The problem would continue if eps(A) > 1e-14 which would be the case if abs(A) > 100 or so
Risposta accettata
Bruno Luong
il 17 Lug 2022
Modificato: Bruno Luong
il 17 Lug 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 Commento
Christine Tobler
il 5 Ago 2022
Più risposte (1)
Steven Lord
il 17 Lug 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.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!