Linear Algebra I · Dot products, orthogonality, and projection

Prerequisites: real coordinate vectors, scalar combinations, matrix multiplication, and bases from the preceding Linear Algebra lessons. Review the Pythagorean theorem and square roots; calculus is not needed. Goals: compute dot products, lengths and distances, test orthogonality, project onto a line, prove the closest-point property, and verify a projection matrix. Read the definitions, trace the diagram, redo the worked examples, run the lab, and attempt practice and the scored assessment independently.

Dot products, lengths, and angles

For u,v in ℝⁿ, define u·v=∑ᵢuᵢvᵢ, a scalar. Inputs must have the same number of components. This product is symmetric and distributes over vector addition; (su)·v=s(u·v). The Euclidean norm is ||u||=√(u·u), and the distance between u and v is ||u−v||. The norm is nonnegative and is zero exactly for the zero vector. Multiplying a vector by s changes its length by |s|, not s when s is negative. These formulas use real coordinates; complex inner products require conjugation and are outside this unit.

Vectors are orthogonal when u·v=0. For nonzero vectors this means a right angle: expanding ||u−v||² and comparing with the cosine rule gives u·v=||u||||v||cosθ. The angle formula requires both norms to be nonzero. The zero vector is orthogonal to every vector by the algebraic definition, although its direction and its angle with another vector are undefined. An orthonormal list is a mutually orthogonal list of unit-length vectors. Orthogonal nonzero vectors are independent: taking the dot product of a zero combination with each vector forces that vector’s coefficient to zero.

Project onto a line through the origin

Let u≠0 define the line span{u}. Write the projected vector as p=cu and the residual as r=v−p. Requiring u·r=0 gives u·v−c(u·u)=0, hence c=(u·v)/(u·u) and p=((u·v)/(u·u))u. The coefficient c is a scalar; p is a vector. The signed scalar component along the unit direction u/||u|| is instead (u·v)/||u||. Do not confuse these three objects. Scaling u by any nonzero factor changes its coefficient but leaves the projected vector unchanged. The formula cannot project onto the zero direction because its denominator would be zero.

0span{u}p=(1,2)v=(3,1)r=(2,−1)u · r = 0
Original diagram with equal coordinate scales. The right-angle mark shows that the remaining error is perpendicular to the line. Here v=p+r and ||v||²=10=5+5=||p||²+||r||².

Why the projection is the unique closest point

Every other point on the line is tu. Since v−tu=r+(c−t)u and r⊥u, expanding the dot product gives ||v−tu||²=||r||²+(c−t)²||u||². The second term is nonnegative and vanishes only at t=c because u≠0. Thus p=cu uniquely minimizes distance over the whole line, including negative coefficients. At t=0, this gives the Pythagorean identity ||v||²=||p||²+||r||². It also proves |u·v|≤||u||||v||: substitute ||p||²=(u·v)²/||u||² and use ||r||²≥0. Equality holds when the residual is zero, meaning v lies on the line; the zero-vector cases also satisfy the inequality.

Projection matrices and orthogonal directions

The transpose uᵀ is the row obtained from column u; Aᵀ swaps the rows and columns of A. For a nonzero column u, P=uuᵀ/(uᵀu) gives Pv=p. The numerator is an n×n matrix; the denominator is a positive scalar. Pᵀ=P, and P²=uuᵀuuᵀ/(uᵀu)²=P. Applying the projection twice changes nothing after the first projection. If n>1, P is singular: a nonzero vector perpendicular to u is sent to zero. Projection onto a line is usually not an invertible transformation.

For mutually orthogonal nonzero u₁,…,uₖ, the projection onto their span is the sum ∑ⱼ((uⱼ·v)/(uⱼ·uⱼ))uⱼ. Each residual dot product with uⱼ vanishes because all cross terms vanish. Do not use this separate-sum formula with a general nonorthogonal basis; the coefficients then interact. The next least-squares lesson develops that case.

Worked examples

  1. Dot product and length: a=(2,−1,2), b=(1,2,0) give a·b=2−2+0=0, so they are orthogonal. Their norms are 3 and √5. The sum is (3,1,2), whose squared norm is 14=9+5, checking Pythagoras.
  2. The diagram’s projection: u=(1,2), v=(3,1) give u·v=5 and u·u=5. Thus c=1, p=(1,2), and r=(2,−1). The check u·r=2−2=0 confirms perpendicularity. The minimum squared distance is 5; choosing t=0 or t=2 instead gives squared distance 10.
  3. Negative coefficient: u=(1,−1), v=(−2,0) give c=−2/2=−1. Hence p=(−1,1) and r=(−1,−1), with u·r=−1+1=0. The nearest point lies in the opposite direction along the line. A projection onto a line is not restricted to a positive ray or to a line segment.
  4. A plane from orthogonal directions: u₁=(1,1,0), u₂=(0,0,2) are orthogonal. For v=(3,1,4), the coefficients are 4/2=2 and 8/4=2. The projection is 2u₁+2u₂=(2,2,4), and residual (1,−1,0) is orthogonal to both directions. Its squared length 2 is the minimum squared error to that plane.

Common mistakes

The projection coefficient divides by u·u, not by ||u||. A zero dot product does not mean either vector is zero. Orthogonality concerns direction, not equal lengths. The zero direction cannot be normalized or used in the projection formula. A zero residual means v is already in the target space, while an orthogonal v projects to zero. A residual perpendicular to one direction need not be perpendicular to a whole plane. In physical models, coordinate units and scaling must make the dot product meaningful; the lab uses dimensionless vectors.

Practice

  1. Warm-up: find a·b and both norms for a=(3,4), b=(4,−3). State whether they are orthogonal.
  2. Project v=(2,1) onto the line through u=(2,0). Give c,p,r and the distance. Explain what happens if u is replaced by (1,0).
  3. For u=(1,1), v=(2,0), find P, verify P²=P, and check the minimum squared distance against trial coefficient t=2.
  4. Challenge: a=(1,0), b=(1,1) are not orthogonal. For v=(0,1), calculate the sum of the two separate line projections. Why is it not the projection onto span{a,b}?
Fully worked solutions
  1. a·b=12−12=0; both norms are √25=5. The nonzero vectors are orthogonal.
  2. c=4/4=1, p=(2,0), r=(0,1), distance 1. With u=(1,0), c becomes 2 but p stays (2,0): changing the direction’s scale does not change the line.
  3. P=(1/2)[1 1; 1 1]. Multiplying gives P²=(1/4)[2 2; 2 2]=P. Pv=(1,1), residual (1,−1), minimum squared distance 2. At t=2, tu=(2,2) and v−tu=(0,−2), so the trial squared distance is 4.
  4. The projection onto a is zero and onto b is (1/2,1/2), so the sum is (1/2,1/2). But a,b span all ℝ², whose projection of v is v itself. The residual (−1/2,1/2) is not perpendicular to a. Separate coefficients work only for mutually orthogonal directions.

Assessment · Open book · 18 points

Open book: use books, lesson notes, cited readings, calculators, and relevant free software. Explain your own reasoning, assumptions, units, and checks; identify references or software you use. Attempt the questions before opening the answer key. Suggested study time: 40–60 minutes; this is a self-study guide, not a timed restriction.

Attempt independently before opening the rubric. Show dot products, restrictions, and residual checks.

  1. For u=(1,2), v=(4,3), find c,p,r and the minimum squared distance. Verify u·r=0. (6)
  2. For u=(1,−1), construct P, verify symmetry and P²=P, and explain why P is not invertible. (4)
  3. Can you use an angle formula for a zero vector? Can you use a zero direction in the line-projection formula? Explain both answers. (2)

Application and reasoning · 6 points

Project v=(3,0) onto u=(1,2) (2). For any trial multiple tu, derive the excess squared error above the optimum (2). A program uses u·v directly as the coefficient; diagnose and quantify its error (2).

Complete answer key and scoring rubric
  1. u·v=10, u·u=5, so c=2 (2). Then p=(2,4) and r=(2,−1) (2). Minimum squared distance is 4+1=5 (1), and u·r=2−2=0 (1).
  2. P=(1/2)[1 −1; −1 1] (1). Pᵀ=P (1), and P²=(1/4)[2 −2; −2 2]=P (1). The nonzero vector (1,1) is sent to zero, so P cannot be invertible (1).
  3. No angle: its denominator contains the zero norm and the zero vector has no direction (1). No zero projection direction: u·u=0 makes the formula undefined; the zero subspace itself has projection zero, treated separately (1).

Application and reasoning · 6 points

c=3/5, p=(3/5,6/5), residual (12/5,−6/5), minimum SSE=36/5 (2). Orthogonality gives ||v−tu||²=36/5+5(t−3/5)² (1 decomposition, 1 factor). Raw dot product 3 omits division by ||u||²=5 (1); it gives p=(3,6), SSE=36, excess 144/5 (1).

Scoring: existing questions 12 + application problem 6 = 18 points. Award the stated method and reasoning marks, not only final answers.

Download the closest-point lab

Download the exact-arithmetic Python lab

Objective: project v=(a,b) onto u=(1,k), check the perpendicular residual and Pythagoras, and compare a trial point tu with the optimum cu. Install free Python 3 for Windows, macOS, or Linux using the official link below. Save the file, open a terminal in its folder, and run the commands; on Windows replace python3 with py -3 if needed. It uses only the standard library, needs no account or paid tools, and runs offline after installation. The arguments k,a,b,t are between −4 and 6; exact fractions such as −1/2 are accepted. The first component of u is always 1, so this lab never divides by a zero direction.

python3 ee-projection.py 2 3 1 0
python3 ee-projection.py 2 3 1 1
python3 ee-projection.py -1 -2 0 0
python3 ee-projection.py 0 2 1 2

Procedure: predict c,p,r and both squared errors on paper. Run each case and repeat the inputs in the browser lab. The first two cases share c=1,p=(1,2),r=(2,−1), best squared error 5; trial t=0 gives 10 and trial t=1 gives 5. The third gives c=−1,p=(−1,1),r=(−1,−1), best error 2 and trial error 4. The fourth gives c=2,p=(2,0),r=(0,1), with both errors 1. The script checks u·r=0, Pythagoras, and trial excess=(t−c)²||u||² exactly. Question: why can no trial give a lower error? The excess is a nonnegative square times the positive number ||u||²; equality requires t=c. This is an idealized, dimensionless modeling activity, not a substitute for sensor calibration or physical measurement skills.

Free primary readings and software

Read p. 1 of MIT’s orthogonality summary for dot products and lengths, then pp. 1–2 of the projection summary for the line formula and matrix properties. The later multiple-column and least-squares portions preview the next lesson. Free summaries, videos, and exercises are available without institutional login or purchase of the suggested textbook.

Projection lab · Compare a trial point with the closest point

Project v=(a,b) onto u=(1,k), check the residual, and compare squared errors.

Free tool built into this page. Use it in your browser without an account or download.

Procedure

Try (k,a,b,t)=(2,3,1,0), (2,3,1,1), (−1,−2,0,0), and (0,2,1,2). Predict the projection and trial error before running. Compare with the downloaded Python lab. Why can the trial never beat the projection?

Expected results and answer check

The first two cases have c=1, projection (1,2), residual (2,−1), and best squared error 5; trial errors are 10 and 5. The third has c=−1, projection (−1,1), best error 2, trial error 4. The fourth has projection (2,0) and both errors 1. The excess is (t−c)²(1+k²)≥0, with equality only at t=c.

Browser values are rounded; the download uses exact rational arithmetic and checks all three identities. Vectors are dimensionless and u=(1,k) is always nonzero. This algebraic model does not simulate sensor noise or replace physical measurement training.