How to have Matlab create a random matrix that is fullrow rank?
21 次查看(过去 30 天)
显示 更早的评论
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 个评论
jessupj
2022-3-24
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.
采纳的回答
Matt J
2022-3-24
编辑:Matt J
2022-3-24
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 个评论
David Goodmanson
2022-3-29
编辑:David Goodmanson
2022-3-30
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
2022-3-30
编辑:Bruno Luong
2022-3-30
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'')');
更多回答(1 个)
Bruno Luong
2022-3-29
编辑:Bruno Luong
2022-3-29
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)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!