Projection Onto a Line: From Sine and Cosine to the Projection Matrix
Why projection appears
After learning that orthogonal complements split a vector into two perpendicular parts, the next question is practical:
Given a vector \(b\), how do we actually calculate its part inside a chosen line or subspace and its perpendicular part?
This operation is called projection.
For a vector \(b\), projection onto a line gives
\[ \boxed{b=p+e} \]
where
- \(p\) is the part of \(b\) along the line,
- \(e\) is the perpendicular leftover part.
Reminder: sine and cosine in a right triangle
For a right triangle with hypotenuse length \(L\) and angle \(\theta\),
\[ \cos\theta=\frac{\text{adjacent}}{\text{hypotenuse}} \]
and
\[ \sin\theta=\frac{\text{opposite}}{\text{hypotenuse}}. \]
Therefore
\[ \boxed{\text{horizontal component}=L\cos\theta} \]
and
\[ \boxed{\text{vertical component}=L\sin\theta}. \]
A useful mental model is
\[ \boxed{\cos\theta=\text{fraction along the reference direction}} \]
and
\[ \boxed{\sin\theta=\text{fraction perpendicular to it}}. \]
For example, if
\[ L=10,\qquad \theta=60^\circ, \]
then
\[ 10\cos60^\circ=5 \]
and
\[ 10\sin60^\circ\approx8.66. \]
So the vector has components approximately
\[ (5,8.66). \]
Why the dot product contains cosine
For two vectors \(a\) and \(b\) with angle \(\theta\),
\[ \boxed{a^Tb=\|a\|\|b\|\cos\theta}. \]
This can be derived by describing the same triangle in two different ways.
The triangle formed by \(a\), \(b\), and \(a-b\) satisfies the law of cosines:
\[ \|a-b\|^2 = \|a\|^2+\|b\|^2-2\|a\|\|b\|\cos\theta. \]
Now calculate the same quantity using the dot product:
\[ \|a-b\|^2=(a-b)^T(a-b). \]
Expanding gives
\[ \|a-b\|^2 =a^Ta-a^Tb-b^Ta+b^Tb. \]
For real vectors,
\[ a^Tb=b^Ta. \]
Therefore
\[ \|a-b\|^2 = \|a\|^2+\|b\|^2-2a^Tb. \]
Compare this with the law of cosines:
\[ \|a\|^2+\|b\|^2-2a^Tb = \|a\|^2+\|b\|^2-2\|a\|\|b\|\cos\theta. \]
Hence
\[ \boxed{a^Tb=\|a\|\|b\|\cos\theta}. \]
So cosine appears because the dot product measures how much one vector points along another vector.
Projection onto the coordinate axes
Take
\[ b= \begin{bmatrix} 2\\3\\4 \end{bmatrix}. \]
Its projection onto the \(z\)-axis is
\[ p_1= \begin{bmatrix} 0\\0\\4 \end{bmatrix}. \]
Its projection onto the \(xy\)-plane is
\[ p_2= \begin{bmatrix} 2\\3\\0 \end{bmatrix}. \]
These add back to the original vector:
\[ \boxed{p_1+p_2=b}. \]
This is the orthogonal-complement decomposition in a particularly easy coordinate system.
Projection onto an arbitrary line
Now suppose the line is not a coordinate axis.
Let a nonzero vector \(a\) specify the direction of the line.
A projection \(p\) onto that line must itself lie on the line.
Therefore \(p\) must be some multiple of \(a\):
\[ \boxed{p=\hat{x}a}. \]
The unknown scalar \(\hat{x}\) tells us how far along the direction \(a\) we must travel.
The error vector
Define the leftover part as
\[ \boxed{e=b-p}. \]
Since
\[ p=\hat{x}a, \]
we have
\[ \boxed{e=b-\hat{x}a}. \]
The closest point on the line occurs when this error vector is perpendicular to the line.
Therefore
\[ \boxed{a^Te=0}. \]
Substitute the expression for \(e\):
\[ a^T(b-\hat{x}a)=0. \]
Expand:
\[ a^Tb-\hat{x}a^Ta=0. \]
Therefore
\[ \hat{x}a^Ta=a^Tb. \]
So
\[ \boxed{\hat{x}=\frac{a^Tb}{a^Ta}}. \]
Since
\[ p=\hat{x}a, \]
the projection is
\[ \boxed{ p= \frac{a^Tb}{a^Ta}a }. \]
This formula is not arbitrary. It comes directly from demanding that the leftover error be perpendicular to the line.
Connection to cosine
Because
\[ a^Tb=\|a\|\|b\|\cos\theta \]
and
\[ a^Ta=\|a\|^2, \]
we get
\[ \hat{x} = \frac{\|a\|\|b\|\cos\theta}{\|a\|^2} = \frac{\|b\|\cos\theta}{\|a\|}. \]
Therefore the length of the projection is based on
\[ \boxed{\|b\|\cos\theta}. \]
This matches the right-triangle idea: cosine gives the component parallel to the chosen direction.
The perpendicular component has length related to
\[ \boxed{\|b\|\sin\theta}. \]
Strang's projection example
Take
\[ a= \begin{bmatrix} 1\\2\\2 \end{bmatrix}, \qquad b= \begin{bmatrix} 1\\1\\1 \end{bmatrix}. \]
Calculate
\[ a^Tb =1(1)+2(1)+2(1) =5. \]
Also
\[ a^Ta =1^2+2^2+2^2 =9. \]
Therefore
\[ \boxed{\hat{x}=\frac59}. \]
The projection is
\[ p=\frac59a \]
so
\[ \boxed{ p= \begin{bmatrix} 5/9\\10/9\\10/9 \end{bmatrix} }. \]
Check the perpendicular error
The error is
\[ e=b-p. \]
Therefore
\[ e= \begin{bmatrix} 1\\1\\1 \end{bmatrix} – \begin{bmatrix} 5/9\\10/9\\10/9 \end{bmatrix} = \begin{bmatrix} 4/9\\-1/9\\-1/9 \end{bmatrix}. \]
Check perpendicularity:
\[ a^Te = 1\left(\frac49\right) +2\left(-\frac19\right) +2\left(-\frac19\right) =0. \]
Therefore
\[ \boxed{e\perp a}. \]
So the decomposition is
\[ \boxed{b=p+e}, \]
with one parallel part and one perpendicular part.
From a projection formula to a projection matrix
We have
\[ p= \frac{a^Tb}{a^Ta}a. \]
Rewrite the scalar and vectors so that \(b\) appears on the far right:
\[ p= \frac{aa^T}{a^Ta}b. \]
This suggests defining the matrix
\[ \boxed{ P=\frac{aa^T}{a^Ta} }. \]
Then projection becomes simply
\[ \boxed{p=Pb}. \]
The matrix \(P\) is called the projection matrix onto the line through \(a\).
Projection matrix for a=(1,2,2)
First calculate
\[ aa^T= \begin{bmatrix} 1\\2\\2 \end{bmatrix} \begin{bmatrix} 1&2&2 \end{bmatrix}. \]
So
\[ aa^T= \begin{bmatrix} 1&2&2\\ 2&4&4\\ 2&4&4 \end{bmatrix}. \]
Since
\[ a^Ta=9, \]
we obtain
\[ \boxed{ P= \frac19 \begin{bmatrix} 1&2&2\\ 2&4&4\\ 2&4&4 \end{bmatrix} }. \]
This one matrix can project any vector \(b\) onto the line through \(a\).
Why P squared equals P
A projection matrix satisfies
\[ \boxed{P^2=P}. \]
The reasoning is geometric.
After one projection,
\[ b\xrightarrow{P}p, \]
and \(p\) is already on the target line.
Projecting \(p\) again does nothing:
\[ p\xrightarrow{P}p. \]
Therefore
\[ P(Pb)=Pb. \]
So
\[ P^2b=Pb \]
for every \(b\), which implies
\[ \boxed{P^2=P}. \]
Why I-P is also a projection
Since
\[ p=Pb, \]
the perpendicular error is
\[ e=b-p. \]
Therefore
\[ e=b-Pb. \]
Factor out \(b\):
\[ \boxed{e=(I-P)b}. \]
So
\[ \boxed{P} \]
projects onto the chosen line, while
\[ \boxed{I-P} \]
projects onto the perpendicular subspace.
Thus
\[ \boxed{b=Pb+(I-P)b}. \]
This is the matrix version of splitting a vector into orthogonal-complement components.
Important mental model
Projection is the practical version of the orthogonal-complement idea.
Instead of only saying that
\[ b=p+e \]
exists, projection tells us how to calculate the pieces.
For projection onto a line through \(a\):
\[ \boxed{ p=\frac{a^Tb}{a^Ta}a } \]
and
\[ \boxed{e=b-p}. \]
The defining condition is
\[ \boxed{a^Te=0}. \]
So the whole construction is built from orthogonality.
Note metadata
- Note type: learning-note
- Subject: learning-notes
- Source: Introduction to Linear Algebra, 5th Edition — Section 4.2 Projections
Related notes
- Orthogonal Complements: Why Row Space and Nullspace Complete Each Other (Post ID: 398)
- Sine, Cosine, SOH-CAH, Vector Components and the Dot Product (Post ID: 386)
- Orthogonality: From Linear Algebra to Quantum States (Post ID: 376)
- Rank Reveals an Invertible Core Inside a Matrix (Post ID: 430)