The set of all $n×n$ matrices having trace equal to zero is a subspace $W$ of $M_{n×n}(F).$ Find a basis for $W.$ What is the dimension of $W?$
To solve this problem, I first noted that the standard basis of $M_{n\times n}(F)$ is $\{E_{ij}\}_{1\leq i,j\leq n}.$
So, the dimension of $M_{n\times n}(F)$ is $n^2.$ Now, I segregated the problem in $2$ cases:
The first case is when $n$ is even. Under this case, what I did was I considered the set $B'=\{E_{ij}\}_{i\neq j}.$ Then I added elements in $B',$ which were $n/2$ number of $n\times n$ matrix :
$$\begin{pmatrix} 1 && 0 && 0 && \cdots && 0 \\ 0 && -1 && 0 && \cdots && 0\\ 0 && 0 && 0 && \cdots && 0 \\ \cdots && \cdots && \cdots && \cdots && \cdots \\ 0 && 0 && 0 && \cdots && 0 \end{pmatrix},$$ $$\begin{pmatrix} 0 && 0 && 0 && 0 && \cdots && 0 \\ 0 && 0 && 0 && 0 && \cdots && 0\\ 0 && 0 && 1 && 0 && \cdots && 0 \\ 0 && 0 && 0 && -1 && \cdots && 0\\ 0 && 0 && 0 && 0 && \cdots && 0 \\ \cdots && \cdots && \cdots && \cdots && \cdots && \cdots \\ 0 && 0 && 0 && \cdots && \cdots && 0 \end{pmatrix},\cdots, $$ $$\begin{pmatrix} 0 && 0 && 0 && \cdots && \cdots && 0\\ 0 && 0 && 0 && \cdots && \cdots && 0 \\ \cdots && \cdots && \cdots && \cdots && \cdots && \cdots \\ 0 && 0 && 0 && \cdots && 1 && 0\\ 0 && 0 && 0 && \cdots && 0 && -1\end{pmatrix}$$
We also append these $n/2$ elements in $B'.$ So, this is a basis for $W.$ The dimension for $W$ is thus, $n^2- n +\frac n2n^2-\frac n2.$
Similarly, we proceed for the case, when $n$ is odd and find the dimension to be equal to $n^2-n+\frac{n-1}{2}+1.$
But the answer given in my book is that the dimension of $W$ is $n^2-1$. I am not getting where I am making the mistake.
Don't view it as a matrix written as a square. Instead view it as an element of $F^{n^{2}}$. So the subspace is $\{(x_{1,1},x_{1,2},...,x_{n,n-1},x_{n,n})\in F: x_{1,1}+x_{2,2}+x_{3,3}+...+x_{n,n}=0$ where $i,i$ denotes the indicies of the elements which represent the $i$-th diagonal entry. So suppose now you were in $F^{4}$ and you are supposed to find the subspace $W=\{(x_{1},...,x_{4})\in F^{4}:x_{1}+x_{4}=0\}$, then how would you do it?
You just get $W=\{(x_{1},x_{2},x_{3},-x_{1}):x_{1},x_{2},x_{3}\in F\}=\text{span}\{(1,0,0,-1),(0,1,0,0),(0,0,1,0)\}$ and that's it. So the dimension is $2^{2}-1=4-1=3 $
In the general case, you see that $W=\{(x_{1,1},x_{1,2},...,x_{n,n})\in F^{n^{2}}:x_{1,1}+x_{2,2}+...+x_{n,n}=0\}$. So now you express $x_{n,n}=-(x_{1,1}+...+x_{n-1,n-1})$
So $W=\{(x_{1,1},x_{1,2},...,x_{n,n-1},-(x_{1,1}+...+x_{n-1,n-1}):x_{1,1},...,x_{n,n-1}\in F\}$ i.e. (you consider all variables except $x_{n,n}$)
So you need $x_{1,1},x_{1,2},...,x_{1,n}, x_{2,1},x_{2,2},...,x_{2,n},.....,x_{n,1},x_{n,2}...,x_{n,n-1}$ many variables to span the space. These are precisely $n^{2}-1$ many in number (i.e. all but the last diagonal entry $x_{n,n}$)
Here is the basis for the $3\times 3$ case.
$\bigg\{\begin{bmatrix} 1 & 0 &0\\ 0 & 0 & 0 \\ 0 & 0 & -1\end{bmatrix} ,\begin{bmatrix} 0 & 1&0\\ 0 & 0 & 0 \\ 0 & 0 & 0\end{bmatrix}, \begin{bmatrix} 0 & 0 &1\\ 0 & 0 & 0 \\ 0 & 0 & 0\end{bmatrix} $
$\begin{bmatrix} 0 & 0& 0\\ 1 & 0 & 0 \\ 0 & 0 & 0\end{bmatrix}\begin{bmatrix} 0 & 0 &0\\ 0 & 1 & 0 \\ 0 & 0 & -1\end{bmatrix} , \begin{bmatrix} 0 & 0&0\\ 0 & 0 & 1 \\ 0 & 0 & 0\end{bmatrix}$
$\begin{bmatrix} 0 & 0& 0\\ 0 & 0 & 0 \\ 1 & 0 & 0\end{bmatrix},\begin{bmatrix} 0 & 0& 0\\ 0 & 0 & 0 \\ 0 & 1 & 0\end{bmatrix}\bigg\}$