# Generate matrices whose null spaces are non-zero integer vectors

I am trying to generate 500 matrices whose null spaces are non-zero, integer vectors.

I currently generate the matrices by using rand() to choose a number between 1 and 5. I find the kernel by passing the matrix to EigenLib's kernel() function. However, my matrix generation algorithm is entirely insufficient because (generally) 19/20 of the kernels are the zero vector.

How do I generate matrices whose null spaces will have integer, non-zero vectors?

• Should the null spaces have a specific dimension? – Rodrigo de Azevedo Jul 17 '17 at 17:28

First choose a column vector $v$ with integer entries that is to be in the null space. Then find a matrix whose rows are orthogonal to $v$. The simplest case will be if some element $v_k$ of $v$ is $\pm 1$. Then you can choose the entries $a_{ij}$ for $j \ne k$ randomly, and take $a_{ik} = \mp \sum_{j \ne k} a_{ij} v_j$.
• $a_{ik}$ is the element that will multiply $v_k$, which is $\pm 1$. – Robert Israel Jul 17 '17 at 19:49
• For example, if your matrices are $3 \times 3$ and $v = \pmatrix{3\cr 2\cr 1\cr}$, you take $a_{i3} = - 3 a_{i1} - 2 a_{i2}$, where $a_{i1}$ and $a_{i2}$ are any integers. – Robert Israel Jul 17 '17 at 19:51