Let be $U=\{ (x,y,z) \: : \: x-z=0\}$, $V=\{(x,y,z) \: :\: z=0\}$ two subspaces of $\mathbb{R}^3$ and $$W=\{f:\mathbb{R}^3 \rightarrow \mathbb{R}^3 \: : f(U) \subseteq V \: \: f(V) \subseteq U \}$$. Find the dimension of $W$ (using its matrix representation)
MY ATTEMPT
Clearly $U=<(1,0,1),(0,1,0)>=<u_1,u_2>$ and $V=<(1,0,0),(0,1,0)>=<v_1,v_2>$. By extending a basis $\{u_1,u_2\}$ of $U$ to a basis $B=\{u_1,u_2,u_3\}$ of $\mathbb{R}^3$ and a basis $\{v_1,v_2\}$ of $V$ to a basis $C=\{v_1,v_2,v_3\}$ of $\mathbb{R}^3$ , the matrix representation should be $$M_C ^B =\begin{pmatrix} a&c&p\\ b&d&q\\ 0&0&r \end{pmatrix}$$ because $f(u_1)$ and $f(u_2)$ must be a linear combination of $v_1$ and $v_2$. By seeing this matrix I can say that the dimension of W is $\dim(W)=7$ (but it's NOT correct, it should be $5$)
I think I'm missing something: how can I use the fact that $f(V) \subseteq U$?
Suppose $e_1 = (1, 0, 1)$, $e_2 = (0, 1, 0)$, $e_3 = (1, 0, 0)$. Then $\mathbb{R}^3 = \langle e_1, e_2, e_3 \rangle$, $U = \langle e_1, e_2 \rangle$, $V = \langle e_2, e_3 \rangle$. Let's change the basis of $\mathbb{R}^3$ to $\{e_1, e_2, e_3\}$. Suppose $T$ is the subspace of linear operators, that are both $U$-invariant and $W$-invariant, $M = \begin{pmatrix} 0 & 0 & 1 \\ 0 & 1 & 0 \\ 1 & 0 & 0 \end{pmatrix}$ in the new coordinates. $\det(M) \neq 0$ and $W = \{AM \mid A \in T\}$. Thus $\dim(W) = \dim(T)$. And one can easily show, that in the new coordinates $$T = \Biggl\{\begin{pmatrix} a_1 & a_2 & 0 \\[-0.4ex] 0 & a_3 & 0 \\[-0.4ex] 0 & a_4 & a_5 \end{pmatrix}\Biggm|\; a_1, a_2, a_3, a_4, a_5 \in \mathbb{R} \Biggr\}.$$ And that means $\dim(T) = 5$, which results in $\dim(W) = 5$.