Ran Wei/ Linear Algebra
中文
Linear Algebra · Structure and approximation

Module 7Orthogonality and QR

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\mathbf b by cuc\mathbf u for nonzero u,\mathbf u\mathclose{\text{,}} choose the point on the line where the residual is perpendicular to u.\mathbf u\mathclose{\text{.}} Solving u⋅(b−cu)=0\mathbf u\cdot(\mathbf b-c\mathbf u)=0 gives

c=u⋅bu⋅u.c=\frac{\mathbf u\cdot\mathbf b}{\mathbf u\cdot\mathbf u}.

For any other point of the line, the squared distance to b\mathbf 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\mathbf u=(1,2)^\mathsf T and b=(3,1)T,\mathbf b=(3,1)^\mathsf T\mathclose{\text{,}} the coefficient is 5/5=1.5/5=1\mathclose{\text{.}} The projection is (1,2)T(1,2)^\mathsf T and the residual (2,−1)T.(2,-1)^\mathsf T\mathclose{\text{.}} 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 QQ stores an orthonormal basis as columns, QTbQ^\mathsf T\mathbf b gives coefficients of the projection. In fact, QTQ=IQ^\mathsf TQ=I and QT(b−QQTb)=0.Q^\mathsf T(\mathbf b-QQ^\mathsf T\mathbf b)=0\mathclose{\text{.}}

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×nm\times n matrix AA with independent columns, this procedure gives A=QRA=QR with QQ of shape m×nm\times n and RR upper triangular of shape n×n.n\times n\mathclose{\text{.}} Column jj of AA combines only the first jj columns of Q.Q\mathclose{\text{.}} 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(3,4)^\mathsf T onto (2,0)T.(2,0)^\mathsf T\mathclose{\text{.}}

Show solution✓ Checked

The coefficient is 6/4=3/2,6/4=3/2\mathclose{\text{,}} so the projection is (3,0)T.(3,0)^\mathsf T\mathclose{\text{.}} The remaining vector (0,4)T(0,4)^\mathsf T is perpendicular to the axis.

Exercise 7.2★★One Gram–Schmidt step

Orthonormalise (1,1)T,(1,0)T(1,1)^\mathsf T,(1,0)^\mathsf T in that order.

Show solution✓ Checked

Normalise the first to (1,1)T/2.(1,1)^\mathsf T/\sqrt2\mathclose{\text{.}} Subtract (1/2,1/2)T(1/2,1/2)^\mathsf T from the second, leaving (1/2,−1/2)T.(1/2,-1/2)^\mathsf T\mathclose{\text{.}} Normalising gives (1,−1)T/2.(1,-1)^\mathsf T/\sqrt2\mathclose{\text{.}}

Exercise 7.3★★★Project twice

Prove (QQT)2=QQT(QQ^\mathsf T)^2=QQ^\mathsf T when QQ has orthonormal columns.

Show solution✓ Checked

Associate the middle factors as QTQ=I.Q^\mathsf TQ=I\mathclose{\text{.}} The product is QIQT.QIQ^\mathsf T\mathclose{\text{.}} 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?
2
Which identity holds for a tall matrix QQ with orthonormal columns?
3
What happens in Gram–Schmidt if the next column is in the previous span?
Finished this module?