How to find the projection matrix onto a subspace
Projecting onto a subspace finds the point in that subspace closest to the vector we start with. We can build one matrix that performs the projection for every input. Let’s form it from a basis for a plane in three dimensions.
Put the basis vectors into a matrix
Use the plane spanned by and . Put these independent vectors into the columns of .
The projection matrix is . The independent columns ensure that is invertible.
Find the small matrix inside the formula
The basis vectors are perpendicular, so their mixed dot products are zero. The diagonal entries are their squared lengths.
Multiply to get the projection matrix
Multiplying the three factors gives the following matrix after multiplying every entry by 45.
Check an input and its perpendicular residual
For , the projection is . The remaining part is . Its dot products with the two basis vectors are zero, so the residual is perpendicular to the whole plane.