I need to find the projection of a vector onto the plane perpendicular to some other vector. Specifically, 
"Calculate the projection of the vector (1,2,3) onto the plane perpendicular to the vector (1,1,1)." 
I am familiar with the projection formula, the projection vector $\mathbf v$ of $\mathbf w$, 
$\mathbf v = P_u \,\mathbf w = A^T(AA^T)^{-1}A \,\mathbf w$, where the rows of matrix A form a basis for the subspace U.   In this case, w = (1,2,3).
I cannot get my head around defining a subspace. From my understanding, the basis of a plane should need only two vectors. Please tell me if I'm wrong about this and why. 
My question is:


*

*How do I define the matrix A based on the plane in the above question?


Thanks.
 A: Caution: in the definition of $A$, it must the columns (and not the rows) of matrix $A$ ...
i.e., matrix $A$ has a rectangular shape  ("portrait format" $3 \times 2$ and not "landscape format" $2 \times 3$) with its 2 columns equal to the basis on the space on which you project, here a plane.
You can take for example:
$$A=\begin{pmatrix}\ \ 1 & \ \ 0\\
                   -1 & \ \ 1\\
                   \ \ 0 & -1
\end{pmatrix}$$
(check that the columns of $A$ are orthogonal to $\begin{pmatrix}1\\
                   1\\
                  1
\end{pmatrix}$)
A: You can get the matrix A as the null-space of $
\left( {\matrix{
   1 & 1 & 1  \cr 
   0 & 0 & 0  \cr 
   0 & 0 & 0  \cr 
 } } \right)
$ ,
i.e. $
\left( {\matrix{
   1 & 1  \cr 
   { - 1} & 0  \cr 
   0 & { - 1}  \cr 
 } } \right)
$, apart for appropriately adjusting for "by-rows" or "by-columns" definition as advised in JeanMarie's answer.
Note that, if you take any invertible matrix that contains the $(1,1,1)$ as first column (or row), then the 2nd and 3rd rows (columns) of its inverse will provide, by definition, such a null-space.
For example:
$$
S = \left( {\matrix{
   1 & 0 & 0  \cr 
   1 & 1 & 0  \cr 
   1 & 1 & 1  \cr 
 } } \right)\quad S^{\, - 1}  = \left( {\matrix{
   1 & 0 & 0  \cr 
   { - 1} & 1 & 0  \cr 
   0 & { - 1} & 1  \cr 
 } } \right)
$$
A: Your question doesn’t say which plane perpendicular to $\mathbf n=(1,1,1)^T$ is meant, but since this doesn’t really affect the projection, let’s assume that the one through the origin was meant—the orthogonal complement of $\mathbf n$. You can use any basis of this space as the columns of the matrix $A$ in your formula.  
The plane define by $\mathbf n$ consists of all solutions to the equation $(1,1,1)^T\cdot(x,y,z)^T=x+y+z=0$.  More generally, to find the orthogonal complement of a set of vectors $\mathbf v_1,\dots,\mathbf v_m$, you would solve the homogeneous system of linear equations $\mathbf v_1\cdot\mathbf x=0,\dots,\mathbf v_m\cdot\mathbf x=0$. The solution to this system consists of all elements of the null space of the matrix that has these vectors as rows, as you probably already know. One can find a basis for this space by row-reducing and reading one from the resulting matrix. We can do the same with one vector: the coefficient matrix is simply the vector itself: $\begin{bmatrix}1&1&1\end{bmatrix}$. This is already in row-reduced echelon form, so we immediately read from it that $(1,-1,0)^T$ and $(1,0,-1)^T$ are a basis for its null space, so one matrix that will work for the projection formula is $$A=\left[\begin{array}{rr}1&1\\-1&0\\0&-1\end{array}\right].$$ More generally, a basis for the orthogonal complement of a vector $(v_1,v_2,v_3,\dots,v_n)^T$ with $v_1\ne0$ is $$\begin{bmatrix}v_2\\-v_1\\0\\\vdots\\0\end{bmatrix},\begin{bmatrix}v_3\\0\\-v_1\\\vdots\\0\end{bmatrix},\cdots,\begin{bmatrix}v_n\\0\\0\\\vdots\\-v_1\end{bmatrix}.$$ (If $v_1=0$, there’s a similar-looking simple pattern that uses the first non-zero slot of the vector instead of the first.)  
You can, however, save yourself some tedious matrix multiplications and inversions by approaching this problem from a different direction. A vector $\mathbf v$ can be decomposed into a component that lies in a subspspace $W$—its projection $P_W\mathbf v$ onto $W$—and a component that’s orthogonal to the space. In our case, this orthogonal component is simply the projection $P_{\mathbf n}\mathbf v$ of $\mathbf v$ onto the plane’s normal vector $\mathbf n$. Therefore, we have $P_W\mathbf v=\mathbf v-P_{\mathbf n}\mathbf v$ (which you might recognize as one of the steps in an iteration of the Gram-Schmidt process). This is known as the orthogonal rejection of $\mathbf v$ from $\mathbf n$. Using the well-known formula for the orthogonal projection of one vector onto another, this can be written as $$P_W\mathbf v=\mathbf v-{\mathbf v\cdot\mathbf n\over\mathbf n\cdot\mathbf n}\mathbf n.$$ If you need the actual projection matrix $P_W$, that can also be computed from the orthogonal projection onto $\mathbf n$. In matrix form, the above equation becomes $$P_W\mathbf v=\mathbf v-{\mathbf n\mathbf n^T\over\mathbf n^T\mathbf n}\mathbf v=\left(I-{\mathbf n\mathbf n^T\over\mathbf n^T\mathbf n}\right)\mathbf v.$$ The parenthesized expression is the matrix for projection onto $W$ and is a lot less work to compute than $A(A^TA)^{-1}A$. To illustrate, for this problem we have $$I-\frac13\begin{bmatrix}1\\1\\1\end{bmatrix}\begin{bmatrix}1&1&1\end{bmatrix}=\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}-\frac13\begin{bmatrix}1&1&1\\1&1&1\\1&1&1\end{bmatrix}=\left[\begin{array}{rrr}\frac23&-\frac13&-\frac13\\-\frac13&\frac23&-\frac13\\-\frac13&-\frac13&\frac23\end{array}\right]$$ which should be the same as the matrix that you got using the other method.
