Project onto a direction or a subspace, build an orthonormal basis, and factor a matrix as QR.
85 minYou need Modules 1, 4 and 5
In this module you will
Compute an orthogonal projection and its residual
Carry out Gram–Schmidt on independent columns
Read the shape and meaning of a thin QR factorisation
1
Drop the perpendicular
To approximate b by cu for nonzero u, choose the point on the line where the residual is perpendicular to u. Solving u⋅(b−cu)=0 gives
c=u⋅uu⋅b.
For any other point of the line, the squared distance to b is the squared length of the same perpendicular residual plus the squared distance along the line. The Pythagorean theorem makes the perpendicular foot the unique closest point.
Example 7.1A projection and its residual✓ Checked
For u=(1,2)T and b=(3,1)T, the coefficient is 5/5=1. The projection is (1,2)T and the residual (2,−1)T. Their dot product is zero.
Try it
Select the Euclidean inner product, then move the target and change the direction of the line. Check that the residual stays perpendicular to the line when its direction is nonzero.
2
An orthonormal basis and Gram–Schmidt
A list is orthonormal when its vectors have unit length and distinct vectors are orthogonal. If Q stores an orthonormal basis as columns, QTb gives coefficients of the projection. In fact, QTQ=I and QT(b−QQTb)=0.
Gram–Schmidt turns independent columns into such a basis. At each step subtract the projection of the next column onto the preceding orthonormal columns. Normalise the residual. Its length is nonzero by independence. The new vectors span the same spaces at each step, since the subtracted vector is in the previous span.
3
The factorisation
For m×n matrix A with independent columns, this procedure gives A=QR with Q of shape m×n and R upper triangular of shape n×n. Column j of A combines only the first j columns of Q. The coefficient of the newest direction is the length of the residual. In floating-point work use a library QR routine. It can use orthogonal reflections to avoid loss of orthogonality when columns nearly depend on each other.
Compute itCheck both properties
Python
from sympy import Matrix
A = Matrix([[1, 1], [1, 0], [0, 1]])
Q, R = A.QRdecomposition()
print((Q.T * Q).tolist())
print(Q * R == A)
Output
[[1, 0], [0, 1]]
True
4
Exercises
Exercise 7.1★Project onto the first axis
Project (3,4)T onto (2,0)T.
Show solution✓ Checked
The coefficient is 6/4=3/2, so the projection is (3,0)T. The remaining vector (0,4)T is perpendicular to the axis.
Exercise 7.2★★One Gram–Schmidt step
Orthonormalise (1,1)T,(1,0)T in that order.
Show solution✓ Checked
Normalise the first to (1,1)T/2. Subtract (1/2,1/2)T from the second, leaving (1/2,−1/2)T. Normalising gives (1,−1)T/2.
Exercise 7.3★★★Project twice
Prove (QQT)2=QQT when Q has orthonormal columns.
Show solution✓ Checked
Associate the middle factors as QTQ=I. The product is QIQT. A second projection therefore leaves the first result in place.
5
Check yourself
1
Why is there a denominator in the projection coefficient onto a non-unit vector?
Solving the perpendicularity condition divides by the vector’s dot product with itself.
2
Which identity holds for a tall matrix Q with orthonormal columns?
Every inner product of distinct columns vanishes and each squared column norm equals one.
3
What happens in Gram–Schmidt if the next column is in the previous span?
Subtracting its projection removes the whole column, so it cannot be normalised.