# Orthogonal Projection of matrix onto subspace

Let's say I have the subspace

$$S=\{(X_1,X_2,X_3,X_4)\mid~~6X_1 - 2X_2 + 4X_3-10X_4 = 0\}$$

How do I go about finding the matrix which is the orthogonal projection onto this subspace?

The relation defining your space is $$X \in S \quad \Leftrightarrow \quad \langle X, (6, -2, 4, -10) \rangle = 0$$ where $\langle \cdot, \cdot \rangle$ is the dot product. So one very obvious guess of a vector that is orthogonal to all $X$ in $S$ is $(6, -2, 4, -10)$. The orthogonal complement of $S$ is, therefore, the space generated by $u = (6, -2, 4, -10)$. (By dimension counting, you know that $1$ generator is enough.) The projection operation is $$P(X) = X - \frac{\langle X, u\rangle}{\langle u, u\rangle}u = X - \frac{uu^T}{u^Tu}X = \left(I - \frac{uu^T}{u^Tu}\right)X.$$
Since your space has codimension $1$ (i.e., dimension $3$ in a $4$-dimensional space), the following recipe will work: find a vector $\tilde e_4$ orthogonal to your subspace (try $(6,-2,4,-10)$), extend to an orthogonal basis $(\tilde e_i)_{i=1,\ldots,4}$ an normalise $e_i=\tilde e_i/ |\tilde e_i|$. Now the coordinates of a vector on this basis are given by scalar products: $v=\sum_{i=1}^4\langle e_i,v\rangle e_i$, and if you leave out $e_4$ you get the orthogonal projection $\sum_{i=1}^3\langle e_i,v\rangle e_i$ of $v$ onto your subspace. In matrix form, take the matrix with columns the coordinates of the $e_i$, and multiply by the matrix with as first three rows the coordinates of $e_1,e_2,e_3$ and last row zero.
Additional exercise: try to find out how to avoid introducing the ugly square roots of the normalization (which should disappear in the final matrix, since your projection is defined over $\Bbb Q$).