Generating a random singular matrices using matlab Could anybody tell me that How one can  generate a random singular matrices using matlab? I know that using rand(n) we can generate a random matrix of order n. But I found that these random matrices are non singular while I am interested in generating random singular matrices of higher order. Is there any command through which we can generate a  random singular matrices? I need help. 
Thanks a lot
 A: If you're not too worried about the distribution of the matrix, you could just generate an $n-1 \times n$ matrix, and let the $n$th row be the sum of the others.
n = 3;
A = rand(n-1,n);
A(end+1,:) = sum(A);

A: If the distribution of the points is not important, you can generate an $n\times n$ matrix with rank $k$ with the following pseudocode.
Generate a random matrix $R$ of dimension $n\times k$.
Set A=R*R^T.

Then $A$ will be an $n\times n$ matrix with rank $k$. This is due to the fact that $A$ is a series of $k$ outer products from the columns of $R$.
A: Another possibility is to take a random $n \times n$ matrix and adjust one entry to make the determinant $0$.  This will be possible as long as the corresponding cofactor is not $0$, which is almost always the case.
A: How are the entries of the matrix generated? Are they Bernoulli / Gaussian / uniform random variables? Whatever the PDF of each matrix entry, here's what you can do:


*

*Generate a random matrix.

*Check if matrix is singular.

*If singular, then use it. If not singular, discard it, and go back to 1.


Of course, you have to think about what "singular" means in MATLAB, for we're using floating-point numbers, not real numbers. Rank lower than eps would do, but it may be too conservative. You would wait a billion years until you found a singular random matrix.
