How can I generate a random triangular matrix? (upper and lower)
Usually I use rand(n)
but if I try tril(rand(n))
it will be singular and I don't want that.
your answer is correct:
A=tril(rand(n))
you can check that this matrix is not singular using
rcond(A)>eps
or
min(svd(A))>eps
and verifying that the smallest singular value is larger than eps, or any other numerical tolerance that is relevant to your needs. (the code will return 1 or 0). For n>50
you'll start to approach singular matrices.
Here's a small analysis of how the matrix approaches singularity with it's size...