BetaFree coursewareRewritten from MIT OpenCourseWareCC BY-NC-SA 4.0
Open CosmologyPhysics & cosmology, from high school to a graduate year

Projections onto subspaces

Projecting b onto the line through a gives the closest point p = x̂a, found from the right angle: the error e = b − x̂a is perpendicular to a, so aᵀ(b − x̂a) = 0 and x̂ = aᵀb/aᵀa. The projection matrix P = aaᵀ/aᵀa has rank one, column space the line through a, and the two defining properties Pᵀ = P and P² = P (projecting twice changes nothing). Doubling b doubles p; doubling a changes nothing. Projections are needed because Ax = b often has no solution: replace b by its projection p onto the column space and solve Ax̂ = p. For a subspace with basis a₁, …, aₙ, the columns of A, the error must be perpendicular to every column: Aᵀ(b − Ax̂) = 0, so e is in N(Aᵀ), the orthogonal complement of C(A). That gives AᵀAx̂ = Aᵀb, x̂ = (AᵀA)⁻¹Aᵀb, p = Ax̂ and P = A(AᵀA)⁻¹Aᵀ, again symmetric with P² = P. The inverse cannot be split unless A is square, and then P = I. The first application, fitting the points (1, 1), (2, 2), (3, 2) by a line b = C + Dt, gives three equations in two unknowns with no solution, to be solved by least squares.

You need this first

Full reading path (16 pages)
  1. Vectors (8.01)
  2. Vectors and the dot product (18.02)
  3. Determinants and the cross product (18.02)
  4. Planes through three points, and matrices (18.02)
  5. Equations of planes and square systems (18.02)
  6. The geometry of linear equations (18.06)
  7. Elimination with matrices (18.06)
  8. Matrix multiplication and inverse matrices (18.06)
  9. Factorization into A = LU (18.06)
  10. Transposes, permutations and vector spaces (18.06)
  11. Column space and nullspace (18.06)
  12. Solving Ax = 0: pivot variables and special solutions (18.06)
  13. Solving Ax = b: the complete solution (18.06)
  14. Independence, basis and dimension (18.06)
  15. The four fundamental subspaces (18.06)
  16. Orthogonal vectors and subspaces (18.06)
On this page · 5 sections
  1. Projecting onto a line
  2. Why project?
  3. Projecting onto a subspace
  4. The first application: fitting a line
  5. Summary

An important lecture, about projections (transcript, p. 1). It continues orthogonal vectors and subspaces, where the equation ATAx^=ATbA^TA\hat x = A^Tb was announced.

Projecting onto a line#

Find the point pp on the line through aa that is closest to bb (transcript, p. 1). (Strang says "closest to a" once; he means bb.) The key is the right angle: the error e=b−pe = b - p is perpendicular to aa (p. 1). Trigonometry with angles would give clumsy formulas; linear algebra does better (p. 2). Since pp is on the line, p=x^ap = \hat xa for some number x^\hat x, and (pp. 2–3)

Projection onto a line
aT(b−x^a)=0  ⇒  x^ aTa=aTb  ⇒  x^=aTbaTa,p=ax^=a aTbaTaa^T(b - \hat x a) = 0 \;\Rightarrow\; \hat x\,a^Ta = a^Tb \;\Rightarrow\; \hat x = \frac{a^Tb}{a^Ta}, \qquad p = a\hat x = a\,\frac{a^Tb}{a^Ta}
In words

a^ capital T the quantity b minus x hat a, equals 0 which gives x hat a^ capital T a equals a^ capital T b which gives x hat equals a^ capital T b over the quantity a^ capital T a, p equals a x hat equals a a^ capital T b over the quantity a^ capital T a

Doubling bb doubles pp; doubling aa (or reversing it) changes nothing, since the line is the same: the factor appears twice above and twice below (pp. 3–4).

The projection matrix (pp. 4–5). pp is a matrix times bb:

Projection matrix onto a line
p=Pb,P=aaTaTap = Pb, \qquad P = \frac{aa^T}{a^Ta}
In words

p equals capital P b, capital P equals a a^ capital T over the quantity a^ capital T a

aaTaa^T is a column times a row, an n×nn \times n matrix, divided by the number aTa=∥a∥2a^Ta = \|a\|^2 (p. 5). Every PbPb lands on the line, so the column space of PP is the line through aa and the rank is 1 (p. 6). Two more facts (pp. 6–8):

Properties of P
PT=P,P2=PP^T = P, \qquad P^2 = P
In words

capital P ^ capital T equals capital P, capital P squared equals capital P

PP is symmetric, and projecting twice gives the same result as projecting once: a point already on the line stays put (p. 7). (The transcript prints capital PP for both the projection and the matrix; Strang says "capital P" for the matrix, p. 8. Here the vector is pp.)

Why project?#

Ax=bAx = b may have no solution, typically when there are more equations than unknowns (transcript, p. 8). AxAx is always in the column space, and bb probably is not. So solve the closest problem that can be solved (p. 9):

The solvable problem
Ax^=p,p=projection of b onto C(A)A\hat x = p, \qquad p = \text{projection of } b \text{ onto } C(A)
In words

capital A x hat equals p, p equals projection of b onto C( capital A )

The hat marks the best possible x^\hat x, not the xx that does not exist (p. 9).

Projecting onto a subspace#

Describe a plane in R3\mathrm{R}^3 by a basis a1a_1, a2a_2, independent but not necessarily perpendicular; it is the column space of A=[a1    a2]A = [a_1\;\;a_2], and the same works for nn columns (transcript, p. 10). If bb is already in the column space, then p=bp = b and e=0e = 0; otherwise the projection is a combination of the columns, p=Ax^p = A\hat x (p. 11). The error e=b−Ax^e = b - A\hat x must be perpendicular to the plane, so to a1a_1 and to a2a_2 (pp. 11–13):

The error is perpendicular to the columns
a1T(b−Ax^)=0,a2T(b−Ax^)=0  ⟹  AT(b−Ax^)=0a_1^T(b - A\hat x) = 0, \quad a_2^T(b - A\hat x) = 0 \;\Longrightarrow\; A^T(b - A\hat x) = 0
In words

a one ^ capital T the quantity b minus capital A x hat, equals 0, a two ^ capital T the quantity b minus capital A x hat, equals 0 which gives capital A ^ capital T the quantity b minus capital A x hat, equals 0

With one column this is the line case again (p. 13). And it fits the four subspaces: ATe=0A^Te = 0 puts ee in N(AT)N(A^T), which is exactly the space perpendicular to C(A)C(A) (pp. 13–14). Rewritten, the key equation and its three answers are (pp. 15–17):

Projection onto C(A)
ATAx^=ATb;x^=(ATA)−1ATb,p=Ax^=A(ATA)−1ATb,P=A(ATA)−1ATA^TA\hat x = A^Tb; \qquad \hat x = (A^TA)^{-1}A^Tb, \qquad p = A\hat x = A(A^TA)^{-1}A^Tb, \qquad P = A(A^TA)^{-1}A^T
In words

capital A ^ capital T capital A x hat equals capital A ^ capital T b; x hat equals ( capital A ^ capital T capital A ) to the power minus 1 capital A ^ capital T b, p equals capital A x hat equals capital A ( capital A ^ capital T capital A ) to the power minus 1 capital A ^ capital T b, capital P equals capital A ( capital A ^ capital T capital A ) to the power minus 1 capital A ^ capital T

ATAA^TA is now an n×nn \times n matrix, so division becomes an inverse; for one column aa these are the line formulas (pp. 15–16).

A tempting mistake (pp. 17–18). Why not write (ATA)−1=A−1(AT)−1(A^TA)^{-1} = A^{-1}(A^T)^{-1}, so that P=AA−1(AT)−1AT=IP = AA^{-1}(A^T)^{-1}A^T = I? Because AA is not square and has no inverse. If AA were square and invertible, its column space would be all of Rn\mathrm{R}^n, and then indeed P=IP = I: projecting onto the whole space changes nothing (p. 18).

The general PP still has the two properties (pp. 18–19). It is symmetric because ATAA^TA and its inverse are; and P2=PP^2 = P because in the product the middle ATAA^TA cancels against (ATA)−1(A^TA)^{-1}:

P squared
P2=A(ATA)−1(ATA)(ATA)−1AT=A(ATA)−1AT=PP^2 = A(A^TA)^{-1}(A^TA)(A^TA)^{-1}A^T = A(A^TA)^{-1}A^T = P
In words

capital P squared equals capital A ( capital A ^ capital T capital A ) to the power minus 1 ( capital A ^ capital T capital A )( capital A ^ capital T capital A ) to the power minus 1 capital A ^ capital T equals capital A ( capital A ^ capital T capital A ) to the power minus 1 capital A ^ capital T equals capital P

The first application: fitting a line#

The most common use is fitting data points that lie close to a line but not on it (transcript, p. 19). Take the points (t,b)=(1,1)(t, b) = (1, 1), (2,2)(2, 2), (3,2)(3, 2) and look for the best line b=C+Dtb = C + Dt (p. 20). (Strang first gives the second point as (2,1)(2, 1) and corrects it.) Going through all three points would need (p. 21)

Three equations, two unknowns
C+D=1,C+2D=2,C+3D=2:(111213)(CD)=(122)C + D = 1, \quad C + 2D = 2, \quad C + 3D = 2: \qquad \begin{pmatrix} 1 & 1 \\ 1 & 2 \\ 1 & 3 \end{pmatrix}\begin{pmatrix} C \\ D \end{pmatrix} = \begin{pmatrix} 1 \\ 2 \\ 2 \end{pmatrix}
In words

C plus D equals 1, C plus 2 D equals 2, C plus 3 D equals 2: 1 1; 1 2; 1 3 C; D equals 1; 2; 2

which has no solution. Multiplying by ATA^T gives the equation ATAx^=ATbA^TA\hat x = A^Tb that can be solved; the numbers come next lecture (pp. 21–22).

Worked example

Projections of your own

(a) Project b=(3,0,3)b = (3, 0, 3) onto the line through a=(1,1,1)a = (1, 1, 1), and write PP. (b) Project b=(1,2,3)b = (1, 2, 3) onto the plane spanned by a1=(1,1,0)a_1 = (1, 1, 0) and a2=(0,1,1)a_2 = (0, 1, 1).

(a) A line

x^=aTb/aTa=6/3=2\hat x = a^Tb/a^Ta = 6/3 = 2, so p=(2,2,2)p = (2, 2, 2) and e=(1,−2,1)e = (1, -2, 1), with aTe=1−2+1=0a^Te = 1 - 2 + 1 = 0. P=13(111111111)P = \frac{1}{3}\begin{pmatrix} 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end{pmatrix}: each entry of PbPb is the average of the entries of bb.

(b) The normal equations

With A=[a1    a2]A = [a_1\;\;a_2]: ATA=(2112)A^TA = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix} and ATb=(3,5)A^Tb = (3, 5). Solving, x^=(13,73)\hat x = (\frac{1}{3}, \frac{7}{3}).

(b) Projection and error

p=13a1+73a2=(13,83,73)p = \frac{1}{3} a_1 + \frac{7}{3} a_2 = (\frac{1}{3}, \frac{8}{3}, \frac{7}{3}) and e=b−p=(23,−23,23)e = b - p = (\frac{2}{3}, -\frac{2}{3}, \frac{2}{3}). Check: a1Te=23−23=0a_1^Te = \frac{2}{3} - \frac{2}{3} = 0 and a2Te=−23+23=0a_2^Te = -\frac{2}{3} + \frac{2}{3} = 0.

Summary#

  • Onto a line: x^=aTb/aTa\hat x = a^Tb/a^Ta, p=ax^p = a\hat x, P=aaT/aTaP = aa^T/a^Ta.
  • Onto C(A)C(A): ATAx^=ATbA^TA\hat x = A^Tb, p=Ax^p = A\hat x, P=A(ATA)−1ATP = A(A^TA)^{-1}A^T; the error ee is in N(AT)N(A^T), perpendicular to C(A)C(A).
  • Every projection matrix has PT=PP^T = P and P2=PP^2 = P; for square invertible AA, P=IP = I.
  • Unsolvable Ax=bAx = b becomes the solvable Ax^=pA\hat x = p: least squares, starting with the best line through data points.

Symbols on this page

Show the 19 symbols used here
⇒\Rightarrow implies.
Implies: what follows is a consequence of what came before. Say it: “which gives”.
×\times times.
Times (multiplication). Between two vectors: the cross product. Say it: “times”.
ı^\hat\imath hat.
A unit vector: a vector of length 1 that only gives a direction (î, r̂). Say it: “hat”.
aa a.
The vector spanning the line that b is projected onto. Say it: “a”.
TT T.
As a superscript: the transpose. Say it: “capital T”.
xx x.
The unknown in Ax = b; with a hat, x̂, the best coefficients of the projection. Say it: “x”.
tt t.
The time (horizontal coordinate) of a data point. Say it: “t”.
nn n.
The number of columns of A; Rⁿ. Say it: “n”.
ee e.
The error vector, e = b − p, perpendicular to the subspace. Say it: “e”.
PP P.
The projection matrix: p = Pb. Say it: “capital P”.
DD D.
The slope of the fitted line b = C + Dt. Say it: “D”.
AA A.
The matrix whose columns span the subspace projected onto. Say it: “capital A”.
CC C.
The intercept of the fitted line b = C + Dt; as in C(A), the column space. Say it: “C”.
bb b.
The vector being projected; the right-hand side of Ax = b. In the line fit, the measured values. Say it: “b”.
NN N.
As in N(Aᵀ): the left nullspace. Say it: “capital N”.
pp p.
The projection of b: the closest point on the line or subspace. Say it: “p”.
a1a_{1} a one.
The first basis vector of the plane (first column of A). Say it: “a one”.
a2a_{2} a two.
The second basis vector of the plane (second column of A). Say it: “a two”.
II I.
The identity matrix. Say it: “capital I”.

Tap or click a symbol in a formula to see the same explanation. All symbols: symbols and notation.

Words on this page

Show the 19 words used here

New here

projection.
The shadow of a vector on a line or plane: the nearest point to it there, found by dropping a perpendicular.

Also used

p..
Page, in a reference to a source; pp. means pages, as in pp. 3–5.
orthogonal.
At right angles; more generally, of two vectors or functions, having a dot product, or an integral of their product, of zero. Explained in Introduction to Fourier series.
vector.
A list of numbers written as a column, or more generally anything that can be added and multiplied by numbers. Explained in Orthogonal vectors and subspaces.
subspace.
A set of vectors inside a larger space that is a space itself: sums and multiples of its vectors stay inside it. Explained in Transposes, permutations and vector spaces.
perpendicular.
At right angles to a line, a surface or another direction. Explained in Inclined planes.
linear.
Of a map, operator or equation: respecting sums and multiples, so that L(au + bv) = aL(u) + bL(v). Explained in The geometry of linear equations.
projection matrix.
A matrix that sends every vector to its projection onto a fixed line, plane or subspace. Explained in Projection matrices and least squares.
matrix.
A rectangular table of numbers, which acts on vectors to give new ones and so describes a linear change of coordinates. Explained in Planes through three points, and matrices.
column space.
All the vectors made by combining the columns of a matrix; Ax = b can be solved exactly when b lies in it. Explained in Matrix multiplication and inverse matrices.
rank.
The number of independent columns of a matrix, which always equals the number of independent rows. Explained in Similar matrices and the Jordan form.
symmetric.
Unchanged by some swap, reflection or turn; for an expression in two quantities, unchanged when they are exchanged. Explained in Introduction to Fourier series.
basis.
A set of independent vectors from which every vector in a space can be built, in exactly one way, as a combination. Explained in Independence, basis and dimension.
inverse.
The thing that undoes another: a matrix times its inverse gives the identity matrix, as a function followed by its inverse gives back the start. Explained in Planes through three points, and matrices.
invertible.
Of a square matrix or operator: having an inverse that undoes it; for a matrix this happens exactly when its determinant is not zero. Explained in The geometry of linear equations.
span.
The span of some vectors is everything that can be made by combining them; vectors span a space when they fill all of it. Explained in Independence, basis and dimension.
least squares.
A way to fit a model to data by choosing it to make the sum of the squared errors as small as possible. Explained in Projection matrices and least squares.

Academic

transcript.
A written record of exactly what was said in a recorded lecture, word for word.
error.
The difference between a measured or computed value and the true one; often how large that difference may be.

Tap or click a word, here or in the text, for its meaning in this lesson. All words: the glossary. How many words are marked in the text: Reading options (the “Aa” button).

Where this leads

In cosmology

31 more cosmology pages that build on this

Pages that build on this

Practise

Check your understanding

  1. Which two properties characterize a projection matrix PP?
  2. If the vector aa is doubled, the projection of bb onto the line through aa…
  3. The error e=b−Ax^e = b - A\hat x lies in which subspace?
0 of 3 answered

Flashcards

1 / 3