How to have Matlab create a random matrix that is fullrow rank?
23 views (last 30 days)
Show older comments
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 Comments
jessupj
on 24 Mar 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.
Accepted Answer
Matt J
on 24 Mar 2022
Edited: Matt J
on 24 Mar 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 Comments
David Goodmanson
on 29 Mar 2022
Edited: David Goodmanson
on 30 Mar 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
on 30 Mar 2022
Edited: Bruno Luong
on 30 Mar 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/945829/image.png)
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'')');
More Answers (1)
Bruno Luong
on 29 Mar 2022
Edited: Bruno Luong
on 29 Mar 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 Comment
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!