Orthonormal columns are the best-behaved columns a matrix can have: QTQ=I, so Q keeps lengths and angles and never amplifies errors. Gram-Schmidt turns any independent columns a1,…,an into orthonormal ones: take q1=a1/∥a1∥, then for each next column subtract its projections onto the q's found so far and normalise what remains.
Recording the numbers you used gives the QR decomposition: Q has the orthonormal columns and R is upper triangular, with Rij=qi⋅aj and the lengths Rjj on its diagonal. For least squares, ∥Ax−b∥=∥QRx−b∥ is minimised by Rx^=QTb, a triangular system solved by back substitution, without ever forming ATA. This is why κ(R)=κ(A) instead of κ(A)2.
Gram-Schmidt on two columnsTake A=(3412), with columns a1=(3,4) and a2=(1,2). Then R11=∥a1∥=5 and q1=(0.6,0.8). Next R12=q1⋅a2=2.2, and a2−2.2q1=(−0.32,0.24) has length R22=0.4, so q2=(−0.8,0.6). Thus Q=(0.60.8−0.80.6) and R=(502.20.4). Check: detA=2=detR.
Q: orthonormal columns, QTQ=I, no error amplification.
R: upper triangular; its diagonal holds the lengths left after removing earlier directions.
Modified Gram-Schmidt (or Householder reflections in libraries) keeps Q orthogonal in floating point; the textbook version loses orthogonality on nearly dependent columns.
Why libraries use QR for regression
Regressors in finance are often nearly collinear (many correlated factors, polynomial features). The normal equations would square that condition number and silently return garbage, while QR (or the SVD) copes. That is the algorithm behind the least squares routines of NumPy and statsmodels, and the one you will build in the capstone.
Lab · what's graded
6 tasks · 100 pts
The first diagonal entry10 pts
The matrix Q20 pts
The matrix R20 pts
A determinant from R15 pts
Least squares with QR15 pts
Why QR is more accurate20 pts
0/ 6 answered
1Numeric answer10 ptsNot answered
Let A=(3412) with columns a1=(3,4) and a2=(1,2). Find R11=∥a1∥.
R11=accepted: ± 0.001
2Matrix · vector20 ptsNot answered
Let A=(3412) with columns a1=(3,4) and a2=(1,2). Run Gram-Schmidt and fill in Q=(q1q2) (decimals are fine).
Q=
3Matrix · vector20 ptsNot answered
Let A=(3412) with columns a1=(3,4) and a2=(1,2). Fill in the upper triangular R so that A=QR.
R=
4Numeric answer15 ptsNot answered
Let A=(3412) with columns a1=(3,4) and a2=(1,2). Since Q is a rotation (detQ=1), ∣detA∣=∣detR∣. Compute it from the diagonal of R=(502.20.4).
∣detA∣=accepted: ± 0.001
5Choice15 ptsNot answered
Given A=QR, which step finds the least squares solution of Ax≈b?
6Explain in words20 ptsNot answered
In two sentences, say why solving least squares with QR is more accurate than with the normal equations.
Math modeKeyboard or LaTeX inputTask 1 of 6 · Ctrl ⏎ to check