Ch4-1 Inner Products in Euclidean Vector Spaces.ipynb
Lab goal
Compute lengths and angles, distinguish orthogonal from orthonormal, and derive a projection by making its residual perpendicular.
Lecture-note concepts
Real inner products
Cauchy–Schwarz
Euclidean norm
Orthogonal complements
Projection onto a line
Code extensionReplace unseeded random vectors with a reproducible 2D example; protect zero-vector normalization and interpret QQT correctly.
Lecture 4 · Reading guide
Read the symbols first
Wooseok Ha, MAS110 Lecture 4 (Fall 2026), lec04.pdf: printed slides 3–6, 12–25, 27, and 30 (PDF pages 5–8, 14–29, 31, and 34).
We keep all vectors real. An inner product is symmetric and bilinear, with ⟨u,u⟩>0 for every nonzero u. Here the standard inner product is uTv. Lab 4.2 keeps the same geometry but changes the inner product to an integral. Our deterministic example v=(2,1)T and u=(1,2)T makes every calculation inspectable.
⟨u,v⟩;∥u∥;u⊥v
An inner product gives one real number, ∥u∥=⟨u,u⟩ is its induced norm, and u⊥v means ⟨u,v⟩=0. The lecture writes |u| for this norm. In Euclidean space the default is uTv and the norm is ∥u∥2; for polynomials it is the stated integral norm.
φ;θ;θ^
This chapter uses φ for an angle and θ for model coefficients in Lab 4.4. The lecture sometimes uses θ for the angle too; the distinction here prevents mixing an angle with a coefficient vector. A hat marks a minimizing coefficient, not a unit vector.
A;G;Q;R;P
A stores input columns in the Euclidean QR and least-squares labs. G denotes a Gram matrix of inner products, including the polynomial metric (which the lecture locally calls A). Q stores orthonormal columns, R stores their reconstruction coefficients, and P projects onto a subspace. These matrices have different jobs and shapes.
u,v∈R2;q=∥v∥2v
u is the vector to project; v is a nonzero direction. q is its unit direction. Dividing by a norm requires a nonzero vector. The zero vector is orthogonal to every vector, but it has no direction or angle.
cosφ=∥u∥2∥v∥2uTv
The formula requires both vectors to be nonzero. Cauchy–Schwarz bounds the ratio by 1 in absolute value. Clip tiny floating-point excursions to [−1,1] before arccos; do not use clipping to hide a zero denominator.
p=λv;λ=vTvuTv;e=u−p
λ is a scalar coefficient, p is a vector on span{v}, and e is the perpendicular residual. For unit q the same vector is p=(qTu)q. The coefficients λ and qTu differ because their basis vectors have different lengths.
Q∈Rm×k;QTQ=Ik
Columns are orthonormal, so k≤m. QQT is the m × m projection onto Col(Q), not a meaningless matrix. It equals Im only when the orthonormal columns span all of Rm; an orthogonal matrix is square.
W⊥;V=W⊕W⊥
W⊥ contains all vectors perpendicular to every vector of W. In finite-dimensional inner-product spaces each vector has a unique decomposition into these two subspaces. Two perpendicular subspaces need not span the whole space.
NumPy: @; np.outer; .T
For two 1D arrays @ is a dot product and returns a scalar. np.outer(q,q) makes the matrix qqT. q.T alone still has shape (2,), so q @ q.T is a scalar, not the projection matrix.
Key ideas
Terms you will use
Inner product⟨u,v⟩=uTv
A scalar comparison satisfying symmetry, bilinearity, and positive definiteness.
Keep in mind The inner product is a scalar; elementwise products form a vector until summed.
Norm and angle∥u∥2=uTu;cosφ=∥u∥2∥v∥2⟨u,v⟩
A norm measures length; a normalized dot product compares directions.
Keep in mind Zero length cannot be normalized and has no angle.
Projectionp=(qTu)q;e=u−p
The component on a subspace leaving a perpendicular residual.
Keep in mind This short formula assumes q has unit norm.
Change the input
See the geometry respond
Keep v=(2,1)T fixed. Rotate u relative to v or change its length. At 90° the projection vanishes; at length zero the angle is undefined.
⟨u,v⟩
4
cosφ
0.8
vTe
0
v · fixed direction
u · input
p · projection
e = u − p · residual
u= (1, 2); p= (1.6, 0.8); e= (-0.6, 1.2). The perpendicularity check stays zero as the input changes.
Lab 4.1 · Euclidean geometry
From two vectors to a perpendicular residual
Use u=(1,2)T and v=(2,1)T to inspect each scalar, vector, and matrix. The formulas are the lecture’s; the small values are a reproducible teaching example.
Select a line to see its action, array shape, and concrete operation.
What does u * v return, and what does u @ v return?
Before
Two vectors, one inner product
Both vectors have two entries. Their inner product will have just one.
u | v
1221
After
?
Reveal to compare.
Connect the steps
Why the dot product determines the geometry
01 Cauchy–Schwarz makes the angle formula possible
If v=0,0≤∥u−tv∥22=∥u∥22−2t⟨u,v⟩+t2∥v∥22 for every real t. At t=⟨u,v⟩/∥v∥22, this implies ⟨u,v⟩2≤∥u∥22∥v∥22. The v=0 case gives 0≤0 directly.
Thus the cosine ratio lies in [−1,1] for nonzero vectors. Scaling a vector by a positive number changes its length, but not its angle with another vector. A negative scale reverses its direction.
∣⟨u,v⟩∣≤∥u∥2∥v∥2;here cosφ=54
02 A unit direction changes the coordinate, not the line
The vectors v and q=v/∥v∥2 span the same line. A coordinate along v is λ=4/5, while the coordinate along q is qTu=4/5. Multiplying either coordinate by its associated basis vector gives p=(8/5,4/5)T.
Orthogonal only means a zero inner product. Orthonormal additionally means unit length. Projection by an inner product alone uses a unit direction; otherwise the denominator ⟨v,v⟩ must remain.
p=vTvuTvv=(qTu)q
03 The perpendicular residual certifies the nearest point
With e=u−λv and λ=⟨u,v⟩/⟨v,v⟩,⟨e,v⟩=0. Any other point μv differs from p only along the line, so its error is the sum of two perpendicular components.
Here e=(−3/5,6/5)T, with squared length 9/5. Every μ other than 4/5 adds a positive squared distance along the line.
∥u−μv∥22=∥e∥22+(μ−λ)2∥v∥22
04QQT is a projection; completing Q changes its range
Because QTQ=Ik,P=QQT satisfies PT=P and P2=Q(QTQ)QT=P. Also Pz lies in Col(Q) and QT(z−Pz)=0. That is exactly orthogonal projection.
The original 4.1 notebook calls a rectangular Q’s QQT meaningless. The corrected interpretation is a projection onto the chosen column space. Completing Q to a square orthogonal basis makes its range the whole space and QQT=Im.
q=51(21)⇒P=51(4221)=I2
05 Perpendicular subspaces and complements are different claims
For U=span{(1,0,0)T} and W=span{(0,1,0)T},U⊥W. But U⊥ is the entire yz-plane; W is only one line in it. A complement must also account for the remaining direction.
For any finite-dimensional subspace W, projection gives u=Pu+(I−P)u. The intersection W ∩ W⊥ is {0}, since a vector perpendicular to itself has zero norm. This proves uniqueness of the decomposition.
Check your understanding
Is the zero vector perpendicular to v? Does it have an angle with v?
Its dot product with v is zero, so it is orthogonal. The angle is undefined because its norm is zero. The explorer reports this case explicitly.
Can you write the projection as (uTv)v?
Only if v is a unit vector. Otherwise divide by vTv. For our v, this denominator is 5.
Are λ and p interchangeable?
No. λ=4/5 is one coordinate; p=λv=(8/5,4/5)T is the projected vector. Changing the basis vector’s length changes the coordinate but not p.
Why is QQT useful when Q has fewer columns than rows?
It projects onto Col(Q). QTQ checks orthonormality in coordinate space; QQT acts in the ambient space. They have different shapes and purposes.
This maintained notebook uses the same notation and worked example as the web lab. Run all cells in order, then change the inputs. NumPy is required; the final plot also uses Matplotlib, available in Colab.