As a simple example we project onto a line. First, calculate e and p.
0000x^(a∙a)x^=e∙a=(b−x^a)∙a=b∙a−ax^∙a=(b∙a)−x^(a∙a)=(b∙a)=a∙ab∙a⟹p=a∙ab∙aae⊥a so the dot product is zeronotice e=b−p=b−x^adistribute anotice x^ is a scalar, so the last term can be x^a∙abecause p=x^a
We can summarize the projection as the matrix p=Pb. This is easy to find if we present the equation the other way around. Notice that with vectors the order is inconsequential, because a∙b=b∙a
00x^(a∙a)x^=a∙e=(a∙b)−x^(a∙a)=(a∙b)=a∙ba∙b=aTaaTba,e on opposite sides
With x^ in this form, we can calculate the projection matrix, P from p=Pb
pp=aaTaaTb=aTaaaTb⟹P=aTaaaTbecause p=Pb
Project Onto a Plane in R3
Note that aTa in the denominator evaluates to a scalar. If we want to project onto a plane, the denominator becomes ATA, which evaluates to a matrix.
Division by a matrix has no meaning. You cannot divide by a matrix.
In arithmetic, we undo multiplication with division.
To undo the effects of a matrix multiplication, we multiply by the inverse of the matrix. A−1Ab=b
We must re-arrange the equation so that we use inverse matrices instead of division.
We can think of projecting onto a plane as projecting onto multiple vectors. To project b onto A, we are looking for the vector x^, such that p=Ax^, where p is the point on the plane closest to b. The first step is to find the vector x^.
Like the first example, we define the error vector, e, as the vector that goes from the plane to b
e=b−Ax^
Assume A is a matrix made of two vectors, a1 and a2 in R3:
A=a11a12a13a21a22a23
Our error vector, e, will be perpendicular to both a1 and a2. We want to find the closest point on A to b. Set e and a perpendicular: 0=anTe
00=a1T(b−Ax^)=a2T(b−Ax^)
There is a simple way to write the equation that captures all components at once.
AT(b−Ax^)
Which can be written as
ATb=ATAx^
Which can be solved for x^
(ATA)−1ATb=x^
Now that we have the x^ vector, we can find the projection matrix. Remember that p=Pb. If we can arrange the equation above correctly, it gives us P.