How to have Matlab create a random matrix that is fullrow rank?
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
DB
el 24 de Mzo. de 2022
Editada: Bruno Luong
el 30 de Mzo. de 2022
Say we have random matrix A, which we use for proving some theory, and we need this matrix to be fullrow rank, how to model this in Matlab?
I have no numeric values, as I want to research the generality of the theory.
2 comentarios
jessupj
el 24 de Mzo. de 2022
can you clarify what you mean by 'random' here? Requiring a rank imposes some constraint (e.g noncollinearity or something like that) on the entries, so they will coordinate with one another rather than being independent. I think this may be one of those things that you have to think out a strategy on paper first before trying to assemble it numerically.
Respuesta aceptada
Matt J
el 24 de Mzo. de 2022
Editada: Matt J
el 24 de Mzo. de 2022
rand() or randn() should give you a full row rank (in probability one) matrix provided there are fewer rows than columns.
rank(randn(3,4))
4 comentarios
David Goodmanson
el 29 de Mzo. de 2022
Editada: David Goodmanson
el 30 de Mzo. de 2022
Hello jessupj,
I am not quite sure what you mean here. The 'should give' that you comment on, it's perfectly fine to replace it with 'will give'. Rand produces something on the order of 10^16 random numbers, meaning that the probability of producing a matrix of any sensible size that is less than full rank is vanishingly small. Creating a matrix that does not obey the desired full rank property is not going to happen. What might conceivably happen, I suppose, is that Matlab assays a full rank matrix as less than full rank due to numerical issues. But that is a different consideration, one of numerical precision rather than truly not satisfying the desired property.
Bruno Luong
el 30 de Mzo. de 2022
Editada: Bruno Luong
el 30 de Mzo. de 2022
By curiosity I run a monte-carlo to see a distribution condition numbers of matrices 1000x1000 generated with of rand(), caution it takes a while for the script to finish; and I get this result of histogram
There is a non negligible cases where the conditionumber goes above 1/eps('single') (1about 10^7). The maximum reaches 1.1263e+09
So for single precision numerical rank is a real problem and cannot be ignored.
ntests=10000;
m=1000;
cs=zeros(1,ntests);
for k=1:ntests,
cs(k)=cond(rand(m,'single'));
end;
figure;
histogram(log10(cs));
xlabel('log_{10} cond');
ylabel('distribution');
title('rand(m,''single'')');
Más respuestas (1)
Bruno Luong
el 29 de Mzo. de 2022
Editada: Bruno Luong
el 29 de Mzo. de 2022
Here is a way to generate finite condition number matrxix , meaning stronger than full rank, and it must give a full rank (unless randn(n) returns all 0s)
targetcond = 10; % must be > 1
n = 1000;
[U,S,V] = svd(randn(n,n), 0, 'vector');
Sc = ((targetcond-1)*S + S(1))/targetcond;
A = U*diag(Sc)*V';
% Check
cond(A)
1 comentario
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!