Q:

Create a system of linear equations with $n$ variables

I have written some function that does matrix computation. I have tested them on $2\times 2,\, 3\times 3,\, 4\times4$ matrices derived from system of linear equations. 
Now, I am having difficulty in finding system of equations in $5,6,7$ etc variables.
Is there a general way by which I can obtain such linear systems which are consistent? 

A:

The general form of a system of linear equations is
$$
A x = b
$$
where $A \in F^{m \times n}$, $x \in F^n$ and $b \in F^m$ and $F$ is some field.
It is consistent, if there exist solutions $x$.
The simplest case, as Travis noted in the comments, are homogeneous systems
$$
A x = 0
$$
because they always have the solution $x = 0$, independent of the choice of $A$.
A nice special case are the systems with $m = n$, thus having the same number of unknowns and (row) equations, which have one solution $x = A^{-1} b$.
You might start with the identity matrix $I_n$ of dimension $n$: 
\begin{align}
& I_n x = b \iff \\
& (I_n \mid b) \iff \\
& (I_n^{(0)} \mid b^{(0)})
\end{align}
and then apply a couple of elementary row transformations:
$$
(I_n^{(k+1)} \mid b^{(k+1)}) = (E_{k+1} I_n^{(k)} \mid E_{k+1} b^{(k)})
$$
where $E_{k}$ does multiply a row by a non-zero scalar multiple or
adds a scalar multiple of another row to a given row.
Such operations do not change the solution set and after a couple of them you should end up with a nice matrix and solution vector, which have not too many zero entries. 
This is basically an inverted Gauss elimination procedure.
If $m > n$ one would start with
$$
\left(
\begin{array}{r|r}
I_n & b \\
0_{(m-n) \times n} & 0_{m-n}
\end{array} 
\right)
$$
and apply elementary row operations $E_k$.
Example:
$$
\left(
\begin{array}{rrr|r}
1 & 0 & 0 & b_1 \\
0 & 1 & 0 & b_2 \\
0 & 0 & 1 & b_3 \\
0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 \\
\end{array}
\right)
$$
If $m < n$ then this has the consequence that $n-m$ variables stay free and can attain arbitrary values.
E.g. if the first $m$ variables are not free then we start with
$$
(I_m 0_{m \times (n-m)} \mid b) 
$$
If we want to bind / free other unknowns $x_i$ then we need to redistribute the $m$ non-zero $1$ entries.
Example:
$$
\left(
\begin{array}{rrrrrr|r}
1 & 0 & 0 & 0 & 0 & 0 & b_1 \\
0 & 0 & 0 & 1 & 0 & 0 & b_2 \\
0 & 0 & 0 & 0 & 1 & 0 & b_3 \\
\end{array}
\right)
$$
Here we have $x_2, x_3$ and $x_6$ as free variables.

