How to have Matlab create a random matrix that is fullrow rank?
23 ビュー (過去 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
![](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'')');
その他の回答 (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)
1 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!