MATLAB: How to random initialize svd function in matlab?

mathematicssignal processing

i want the svd function in matlab to give me two different values for the same matrix , i mean the U and V , currently im getting the same everytime i run

Best Answer

The linear algebra functions in MATLAB are run-to-run reproducible, meaning if you call them twice with the exact same input, you get the exact same output.
If you want to randomize the output, you could pre-multiply the matrix with two random orthogonal matrices, and then apply does matrices to the outputs U and V:
[m, n] = size(A);
U0 = orth(randn(m));
V0 = orth(randn(n));
[U, S, V] = svd(U0*A*V0');
U = U0'*U;
V = V0'*V;
norm(A - U*S*V', 'fro')
This will still return the same singular values (which are unique), but returns different singular vectors.