5
votes

How would you generate a random matrix that is not singular in MATLAB.?

I know a matrix determinant can be used to do check this, but after reading MATLAB determinant:

"Using det(X) == 0 as a test for matrix singularity is appropriate only for matrices of modest order with small integer entries. Testing singularity using abs(det(X)) <= tolerance is not recommended as it is difficult to choose the correct tolerance. The function cond(X) can check for singular and nearly singular matrices."

So if I want to generate a big random matrix (axb) a=5000, b=5000, How to do it??.

1
A singular matrix is not invertible. So, what did you mean by "not singular (not invertible)"?Jacob
yes, I did not explain it the right way. Already modifiededgarmtze
For such a large matrix, determining exact singularity is likely limited by your numerical precision. As the manual says, your best bet is to check that cond(X) is within what your application can tolerate. If you just want to theoretically avoid singularity, any finite condition will do; as the answer says, accidentally generating an exactly singular matrix is vanishingly unlikely.comingstorm

1 Answers

14
votes

A randomly generated matrix will be full rank (and hence invertible, if square) with probability 1:

A = randn(5000);

you can check this by using min(svd(A)), and verifying that the smallest singular value is larger than zero.

This is a well-known fact, but here's an example paper if you want one.