Degrees of freedom in a $n \times n$ table Suppose we have an $n \times n$ table where each row and each column sums to some number $k$. Say that the elements of the table and $k$ are real numbers. Now the question is how many places can we fill in the table in any way such that the remaining places can be filled in a way such that the sums are correct. This is what we call the degree of freedom. The top left $(n - 1) \times (n - 1)$ subrectangle can be filled out in any way and we can always extend it to a good solution so the degree of freedom is at least $(n - 1)^2$. Also there must be an element missing from each row and each column. So the degree of freedom is at most $n^2 - n$. I've read that the degree of freedom is $(n - 1)^2$ but there was no proof supported and this is how far I've got. Could someone give me a hint on this?
 A: So I have a solution using linear algebra. We need to solve the following linear equations(row sums):
$$\forall i \in 1\dots n \sum_{j = 1}^{n}x_{i,j} = k$$
and(column sums)
$$\forall j \in 1 \dots n \sum_{i = 1}^{n}x_{i, j} = k$$
If we want to prove the claim we have to prove that the matrix here has rank $2n - 1$. It's easy to see that the first $n$ equations are independent. Same goes for the second $n$ equations. The following is also true:
$$\sum_{i=2}^{n}\sum_{j=1}^{n}x_{i, j} - \sum_{j=1}^{n}\sum_{i=1}^{n}x_{i,j} = \sum_{j=1}^{n}x_{1,j}$$
Basically this means that the first row sum equals the next $n - 1$ row sums minus the column sums. For clarification the matrix for $n = 3$ looks like this(when the variables are in row continuous order):
$$\begin{matrix}
1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 1 & 1 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 \\
1 & 0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 \\
0 & 1 & 0 & 0 & 1 & 0 & 0 & 1 & 0 \\
0 & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 1 \\
\end{matrix} $$
And I guess it's easy to see that the rest of the $2n - 1$ rows are independent since the last $n$ rows have a unique element in the first $n$ columns of the matrix and the rows $2$ to $n$ are all zeroes in these columns.
