Artificial intelligent assistant

Generate arbitrary numerically invertable matrix I'm designing a unit-test for a matrix inversion function. Currently I make a random matrix as a test case by generating its elements with random numbers uniformly distributed in $[0,1)$. If I stopped here, there would be a small, but non-zero, chance that the resulting matrix will be numerically ill-conditioned for inversion. I know that I can solve this problem by diagonal loading of the matrix, i.e. adding a value $c$ to the diagonal elements $M_{ii}$. Is there an easy way to compute that amount of diagonal loading $c$ that I can add to such a random matrix to ensure that it is not (numerically) ill-conditioned for inversion? My hunch is that the size of $c$ depends (at least) on the size of the matrix $N$, but I don't know how to derive the relationship. Also note, that I'm not trying to find a smallest $c$ for the specific matrix under consideration, but rather a general $c$ applicable to any of my random matrices.

It sounds like you want the Gershgorin circle theorem. Since all the off-diagonal matrix entries are at most $1$, you can guarantee that no eigenvalue of your matrix is too small by ensuring that all the diagonal entries are substantially larger than $N-1$.

That is, taking $c=N$ should suffice.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 11ddb314700de0b3a68d40fa4b873240