Explain each entry of Q and R, check orthonormality separately from reconstruction, and connect the QR projection to least squares.
Lecture-note concepts
Gram–Schmidt
Nested spans
Reduced QR
Orthogonal matrices
Numerical orthogonality
Code extensionTrace the lecture’s 3 × 2 example before inspecting near-dependent columns. Add a scale-aware normalization check including the first column.
Lecture 4 · Reading guide
Read the symbols first
Wooseok Ha, MAS110 Lecture 4 (Fall 2026), lec04.pdf: printed slides 34–37, 47, 49–51 (PDF pages 39–42, 55, 57–59). This is the same A used for projection and least squares in 4.4.
The matrix A has m=3 rows and n=2 independent columns. Gram–Schmidt replaces its columns by an orthonormal basis for the same column space; R records the coefficients needed to reconstruct the original columns. The lecture calls the normalized Gram–Schmidt vectors wi before naming the QR columns qi. We consistently use qi for normalized directions and wj for an unnormalized remainder.
⟨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.
A=[a1∣a2]∈R3×2
aj here means column j, a vector in R3. In the statistical model of 4.4, the lecture also names a row feature vector ai via row aiT. Check the index and shape: columns are feature directions in measurement space; rows collect features for one measurement.
wj;qj=∥wj∥2wj
wj is what remains after removing all earlier orthonormal components of aj. qj has unit length; wj generally does not. This normalization needs a nonzero remainder. Independent columns guarantee it in exact arithmetic.
rij=qiTaj(i<j);rjj=∥wj∥2
These scalars are the reconstruction coefficients. With the positive-diagonal Gram–Schmidt convention, rjj>0. A library can use different matching signs; that does not change QR or the column space.
Q∈Rm×n;R∈Rn×n,m≥n
For full column rank, reduced Q has n orthonormal columns and reduced R is invertible and upper triangular. QTQ=In. For m > n, Q is rectangular and QQT=P, not Im.
Complete QR;Qfull∈Rm×m
Complete Q extends the basis to all of Rm;Rfull has shape m × n. The extra Q columns do not all belong to Col(A). QfullQfullT=Im, whereas projection onto Col(A) uses only the relevant column-space basis.
ε; numerical threshold; matrix rank
ε is a small parameter in the near-dependent example, not a residual vector. In floating point a tiny remainder can indicate numerical dependence. The demonstration routine compares against a threshold scaled by the matrix norm; it is a teaching rank policy, not an exact symbolic rank test.
np.linalg.qr(A, mode="reduced")
This returns a reduced factorization using LAPACK routines. Rank-deficient matrices still have QR factorizations, but R is singular and extra Q directions need not lie in Col(A). The full-column-rank solve Rθ=QTb then cannot be used as an invertible solve.
Key ideas
Terms you will use
Gram–Schmidtwj=aj−∑i<j(qiTaj)qi
Remove each old orthonormal component, then normalize the new information.
Keep in mind A zero remainder cannot be normalized.
Reduced QRA=QR;QTQ=In
An orthonormal column basis and the triangular coefficients reconstruct the input.
Keep in mind Reduced Q is rectangular when m > n.
Two numerical checks∥A−QR∥;∥QTQ−I∥
Measure reconstruction separately from orthonormality.
Keep in mind One small error does not establish the other.
Change the input
See the geometry respond
This is the plane of the lecture’s columns, shown in its orthonormal q1,q2 coordinates. The initial angle 120° gives the lecture’s exact components. Change the angle to see when the second column adds a new direction.
Step 1 of 3 · original columns
r12
-0.70711
r22=∥w2∥2
1.22474
Column rank
2 · independent
a1 · first column
a2 · second column
a2=−0.70711q1+1.22474q2. The normalization changes the remainder’s length to 1, while R keeps the original scale.
Lab 4.3 · Lecture QR example
Build the two columns of Q and read R
Keep the lecture’s A=[[−1,1],[0,1],[1,0]] throughout. The same column-space basis leads directly to Lab 4.4.
Select a line to see its action, array shape, and concrete operation.
Maintained notebook·Ch4-3 QR-Decomposition.ipynb ↗Contains guarded Gram–Schmidt routines, rank-deficient cases, and the near-dependent numerical example.
L01 / 24Name the input columns
Predict
Why do a1 and a2 each have three entries?
Before
Two independent directions in R3
A has two columns with three entries each. Reduced Q will also have shape (3,2), while R has shape (2,2).
A
-110110
After
?
Reveal to compare.
Connect the steps
Why Gram–Schmidt produces QR
01 Subtracting old components creates a new perpendicular direction
Set wj=aj−∑i<j(qiTaj)qi. Pair it with any earlier qk. Orthonormality cancels exactly the matching term, leaving qkTwj=0. If wj were zero, aj would already be in the preceding span, contradicting independence.
Dividing by ∥wj∥2 gives a unit vector. The same argument applies to the first column with an empty sum: a zero first column must be caught before normalization.
aj=∑i<jrijqi+rjjqj
02 The nested spans make R upper triangular
Each qj is formed using a1,…,aj, and each aj can be reconstructed using q1,…,qj. Therefore the two prefixes have the same span. No later direction is needed to reconstruct an earlier column.
Collect these reconstruction coefficients as column j of R. All entries below the diagonal are zero. The nonzero diagonal makes R invertible under the independent-column assumption.
span{a1,…,aj}=span{q1,…,qj};A=QR
03 Follow the lecture’s second column exactly
The first normalized column is q1=(−1,0,1)T/2. The second coefficient is r12=q1Ta2=−1/2. Subtracting r12q1 from a2=(1,1,0)T leaves w2=(1/2,1,1/2)T.
Its length is 6/2, so q2=(1,2,1)T/6. The negative coefficient is allowed: the component of a2 along q1 points in the opposite direction.
a2=−21q1+26q2
04 Orthonormal coordinates simplify projection and fitting
Because QTQ=I2, the coordinates of the projection of b onto Col(A) are QTb. The fitted vector is QQTb. If Aθ^ equals that fitted vector, then QRθ^=QQTb, so multiplying by QT gives Rθ^=QTb.
For b=(1,1,1)T, this produces θ^=(2/3,4/3)T, exactly the 4.4 example. QTb are basis coordinates in q1,q2;θ^ are coefficients of the original columns a1,a2. They are not the same vector of numbers.
QTb=(04/6);Rθ^=QTb;b^=QQTb
05 Factorization error and orthogonality error test different things
A small ∥A−QR∥ says the factors reconstruct the input. It does not guarantee a small ∥QTQ−I∥. Classical Gram–Schmidt can lose orthogonality for near-dependent columns through cancellation, even while reconstructing A accurately.
Modified Gram–Schmidt computes each projection from the updated remainder. It often improves numerical orthogonality, but severe conditioning can still require reorthogonalization. Use a library QR for practical factorization. The companion notebook compares both errors on the original ε=10−8 example instead of relying on one allclose check.
06 Dependent columns change the full-column-rank algorithm, not the existence of QR
If a2=2a1, its remainder after subtracting the q1 component is zero. The teaching routine stops instead of dividing by zero; there is no second independent direction in the column space.
QR still exists: a library may complete Q with an arbitrary perpendicular direction while making R singular. Then using all columns of that Q in QQT can project onto a larger space than Col(A). A rank-r basis Qr gives the correct P=QrQrT; lstsq handles the fit without requiring an invertible R.
Check your understanding
Must the lecture’s Q match NumPy’s Q entry for entry?
No. A column sign in Q can be reversed if the corresponding row of R is reversed. Check A≈QR,QTQ≈I, and the projection instead.
Why is R upper triangular?
Column aj is already in span{q1,…,qj}. It has no component along any later qi, so rij=0 when i > j.
What fails when the first column is zero?
Its norm is zero, so even the first normalization is invalid. A guard only inside the later-column loop misses this case.
Does small A − QR imply QTQ is close to I?
No. Reconstruction and orthogonality are different properties. Near-dependent columns can expose a large orthogonality error even with a small reconstruction error.
Do dependent columns mean there is no QR factorization?
No. They mean R is singular and the full-column-rank algorithm cannot make every input column contribute a new direction. Any extra Q columns need not belong to Col(A).
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.