# Finding distance between a vector and a subspace

Let the inner product of $V=M_3(\mathbb{R})$ to be $\langle A,B\rangle =\mathrm{trace} (A^tB)$.

I need to fine the distance between $X= \begin{pmatrix} 2 & 1 &0 \\ 0&-1 &2 \\ 1& 0 & 1 \end{pmatrix}$ and the subspace $U= \bigl\{A\mid \mathrm{trace}(A)=0\bigr\}$ of $V$.

From what I know I can find it by calculating $\left\lVert\frac{\langle w,A\rangle w}{\lVert w\rVert^2}\right\rVert$ where $\mathrm{span}(w)=U^\perp$, but how can I find $w$, and why should it be only one vector only?

-
Another way to look at this is to observe that $tr(A^TB)=\sum_{i,j}a_{ij}b_{ij}$. So you really have the usual inner product of $\mathbf{R}^9$. $U$ is the set of solutions of a single homogeneous linear equation, so has dimension 8. – Jyrki Lahtonen Aug 8 '11 at 21:10

The trace is a linear map from $V$ onto $\mathbb{R}$; that means that $U$ has dimension $8$, since it is equal to the kernel of this map.

The orthogonal complement will then be spanned by a single vector. You can find such a vector by finding one which is orthogonal to each vector in a basis for $U$. For example, you can take as your basis $E_{12}$, $E_{13}$, $E_{21}$, $E_{23}$, $E_{31}$, $E_{32}$, $E_{11}-E_{22}$, and $E_{11}-E_{13}$. This will give you information about $w$.

For instance, the fact that $\langle E_{12},w\rangle = 0$ tells you that the $(1,2)$ entry of $w$ must be equal to $0$. Using the rest of the basis, you should get all the information you need about the structure of $w$.

Or you could realize that there is a very special set of matrices $M$ such that for all $A$, $\mathrm{trace}(A)=0$ if and only if $\mathrm{trace}(M^tA) = 0$, and go from there. Hint. Do you know some family of matrices for which it is easy to compute the trace of $M^tA$ in terms of the trace of $A$?

-
Ok, so beacuse $V=U\oplus U^\perp$ I can take $w=E_{11}+E_{22}+E_{33}$ for example? – user6163 Aug 8 '11 at 19:27
Your $w$ is correct, your reasoning is not. For any finite dimensional space $V$ and finite dimensional subspace $U$, you have $V=U\oplus U^{\perp}$. The reason you can take $w$ as given here is because $\dim(U^{\perp})=1$, $w\perp U$, and $w\neq \mathbf{0}$. – Arturo Magidin Aug 8 '11 at 19:33
should I make w orthonormal or orthogonal will do? – user6163 Aug 8 '11 at 19:37
@Nir: Well, why don't you look at the formula you want to use and figure out whether it requires or assumes that $w$ is orthonormal or not? – Arturo Magidin Aug 8 '11 at 19:38
OK............. – user6163 Aug 8 '11 at 19:48