Fundamentals / Numerical mathematics / Numerical linear algebra

Householder reflections and practical QR

Build one reflection explicitly, use it to triangularise a rectangular system and locate the residual in transformed coordinates.

From first principles

Construct a reflection that zeros a column tail

A reflection reverses the component of a vector perpendicular to a chosen plane and leaves the component in the plane fixed. If a nonzero vector \(v\) is normal to the plane, the perpendicular projection of \(x\) is \(v(v^Tx)/(v^Tv)\). Subtracting twice that projection defines

\[Hx=x-2v\frac{v^Tx}{v^Tv},\]
\[H=I-2\frac{vv^T}{v^Tv}.\]

The reflection preserves lengths because the parallel and perpendicular components remain orthogonal. To reduce a column \(x\), target an axis vector \(y=\alpha e_1\) of equal length, so \(|\alpha|=\|x\|_2\). Set \(v=x-y\). Expanding the dot products gives \(2v^Tx=v^Tv\) because \(x\) and \(y\) have equal norm. Consequently

\[Hx=x-v=y .\]

Choosing \(\alpha\) opposite in sign to \(x_1\) avoids cancellation in \(v_1\). Reflecting only the unprocessed rows of each successive column yields an upper triangular factor while preserving previously generated zeros. An already zero column needs no transformation.

Derivation and applications

Recover the least-squares residual from Householder coordinates

A QR solver can report how much an orthogonal transformation sends into rows below a triangular factor. That part has a precise measurement interpretation. Assume a real matrix \(A\) with \(m>n\) and independent columns. Apply the same sequence of Householder transformations to the augmented matrix \([A\ b]\). Their product \(Q^T\) is orthogonal. Partition its result into an upper block with \(n\) rows and a lower block,

\[Q^T[A\ b]=\begin{pmatrix}R&c\\0&d\end{pmatrix}.\]

Because orthogonal transformations preserve the Euclidean norm, the squared residual of any trial vector decomposes into the sum of two nonnegative terms. Only the first can be changed by the fit,

\[\|b-Ax\|_2^2=\|c-Rx\|_2^2+\|d\|_2^2 .\]

The optimal \(x\) solves \(Rx=c\), leaving residual norm \(\|d\|_2\). In exact arithmetic the original-coordinate residual is obtained by reversing the transforms on a vector whose upper block is zero,

\[r=b-Ax=Q\binom{0}{d},\]
\[A^Tr=R^T[\,I\ \ 0\,]\binom{0}{d}=0.\]

The lower coordinates are combinations of observations. Their individual values depend on the particular reflections, whereas their squared norm is invariant. Retaining that norm directly avoids subtracting two large nearly equal squared norms when the fit is excellent. If some triangular pivots are numerically negligible, ranking the columns and checking the model’s effective rank become necessary before interpreting all \(n\) fitted coefficients.

Worked example

Inspect residuals after fitting a constant

Fit \(A=(1,1)^T\) to readings \(b=(8,10)^T\). Rotate to the orthonormal directions \((1,1)/\sqrt2\) and \((-1,1)/\sqrt2\). The transformed data are \(18/\sqrt2\) and \(2/\sqrt2\), while the transformed model is \((\sqrt2,0)^T x\). The fit gives \(x=9\), residual norm \(\sqrt2\), and original residual \((-1,1)^T\). Its sum is zero as the constant column requires.

Second application

Compare the numerical consequences of subtracting squared norms

Suppose transformed coordinates of another fit have \(\|c\|=10^8\) and \(\|d\|=0.1\). Computing \(\|b\|^2-\|c\|^2\) would subtract two values near \(10^{16}\) to recover \(0.01\). Binary64 spacing near \(10^{16}\) is 2, so the small addition can disappear entirely. Keeping the transformed tail returns residual norm \(0.1\) directly, subject to normal transformation errors.

Eliminate a column without stretching it

An orthogonal transformation applied simultaneously to the data matrix and right-hand side leaves every Euclidean residual length unchanged. A Householder reflector is \(H=I-2vv^T/(v^Tv)\) for a nonzero vector \(v\). Decompose any vector into components parallel and perpendicular to \(v\). The parallel component changes sign and the perpendicular component stays fixed, proving both length preservation and \(H^2=I\). Implementation requires just a dot product and a scaled vector subtraction rather than a dense matrix.

To make the entries below the first element of a column \(x\) vanish, choose \(v=x-\alpha e_1\) where \(|\alpha|=\|x\|_2\). A short calculation gives \(v^Tv=2(\|x\|^2-\alpha x_1)\) and \(v^Tx=\|x\|^2-\alpha x_1\), hence

\[Hx=x-v=\alpha e_1.\]

Choose \(\alpha\) with sign opposite to \(x_1\) to avoid subtracting nearly equal positive numbers when computing \(v_1\). A zero column requires a separate decision about rank.

Follow the data into the triangular system

For \(x=(3,4)^T\), use \(\alpha=-5\) and \(v=(8,4)^T\). The reflection matrix is \(\left(\begin{smallmatrix}-.6&-.8\\-.8&.6\end{smallmatrix}\right)\). Take a one-column least-squares problem with measurements \(b=(4,3)^T\). Multiplication sends \(x\) to \((-5,0)^T\) and \(b\) to \((-4.8,-1.4)^T\). The optimum coefficient matches the first transformed measurement, giving \(c=0.96\). The second transformed measurement remains a residual of magnitude 1.4. Back in physical coordinates the predicted vector is \((2.88,3.84)\), with residual \((1.12,-0.84)\) and the same length.

For several columns, apply the first reflector to the entire remaining block. Construct the next reflector only on rows below the first pivot, protecting the already triangular part. Saving the reflector vectors permits application of \(Q\) or \(Q^T\) later without explicitly forming either full matrix. Additional right-hand sides can then use the same orthogonal transformations and triangular solve.

Detect when a coefficient is poorly determined

If a new column is nearly in the span of earlier columns, little of it survives below the preceding pivots. A small trailing diagonal of \(R\) signals potential coefficient sensitivity, but its scale depends on column units and order. An instrument model with one parameter measured in micro-units can naturally have a small column. Scale the columns according to the intended range of the corresponding parameters before interpreting a near-zero diagonal.

Column-pivoted QR selects a remaining column with a large unrepresented component at each stage. It can help reveal effective rank and identify an independent set of measurements or basis functions. A numerical rank decision still needs a tolerance tied to data uncertainty or floating-point arithmetic. Reporting a fitted coefficient to ten digits after discarding an almost invisible direction would conceal the limitation that the factorisation has revealed.

Check a nearly aligned column

Consider \(x=(1,10^{-8})^T\). Its norm differs from one by only about \(5\times10^{-17}\), below the spacing between one and the next larger double precision number. Computing the exact difference \(x_1-\|x\|\) as that subtraction may therefore give zero. Choosing the target with opposite sign makes the first entry of the reflector vector about two and the remaining small entry is retained. This calculation explains the sign convention geometrically: two opposite points on a sphere provide valid reflection targets, and only one directs the subtraction away from severe cancellation.

Update a triangular fit when observations arrive sequentially

A Householder QR factorisation is efficient when the entire design matrix is available. Suppose instead that a new row arrives after the original observations have been reduced to an upper triangular factor \(R\), a transformed data vector \(z\), and an accumulated residual sum of squares \(S\). The original least-squares objective equals \(\|Rx-z\|^2+S\). Appending measurement row \(a^T\) and value \(b\) adds \((a^Tx-b)^2\). Stacking \(a^T\) below \(R\) produces a matrix that is triangular except for one row. Orthogonal plane rotations can restore triangular form by eliminating each incoming entry in turn.

To remove a pair \((r,s)^T\), let \(\rho=\sqrt{r^2+s^2}\), \(c=r/\rho,\ d=s/\rho\). Multiplication by the rotation with rows \((c,d)\) and \((-d,c)\) gives \((\rho,0)^T\). Apply precisely the same two-row operation to all remaining columns and to the transformed data. Its final bottom data entry has no corresponding design column, so its square adds to \(S\). If \(r=s=0\) there is nothing to eliminate. A numerical implementation obtains the length with a scaled hypotenuse evaluation to avoid overflow from squaring a large observation.

Insert a point into an existing two-parameter fit

Suppose the existing transformed problem has \(R=I,\ z=(1,2)^T,\ S=0\). A new sensor reports \(x_1+x_2=5\). The best prior estimate was \((1,2)^T\), which predicts three and therefore disagrees with the incoming reading by two. To reconcile all observations, stack the new row \((1,1\mid5)\) below \((1,0\mid1)\) and \((0,1\mid2)\). Rotate the first and last rows with \(c=d=1/\sqrt2\). The first becomes \((\sqrt2,1/\sqrt2\mid6/\sqrt2)\); the last becomes \((0,1/\sqrt2\mid4/\sqrt2)\).

The second rotation combines leading entries \(1\) and \(1/\sqrt2\), yielding \(\rho=\sqrt{3/2}\), \(c=\sqrt{2/3}\), \(d=1/\sqrt3\). Its surviving right-hand side is

\[2\sqrt{2/3}+4/\sqrt6=8/\sqrt6.\]

Thus the second-coordinate estimate is

\[(8/\sqrt6)/\sqrt{3/2}=8/3.\]

Back substitution in the first row gives

\[x_1=(6-8/3)/2=5/3.\]

The final bottom data entry is \(-2/\sqrt3+4/\sqrt3=2/\sqrt3\), contributing \(4/3\) to the residual sum of squares.

Verify directly: the three residual magnitudes are all \(2/3\), so their squared sum is \(4/3\). The new reading moved both coordinates equally because their original transformed information was identical and its row is symmetric. No historical measurement needed to be reread. Conversely deleting an earlier reading can expose rank deficiency and is a different numerical operation; simply running the same update with a negated data value would add another squared term rather than remove information.

When a stream contains different measurement variances, divide each arriving row and its right-hand side by its independently known standard deviation before applying the rotations. The accumulated \(S\) then measures squared standardised discrepancies. If the new reading shares an error with earlier readings, dividing its row alone is insufficient. One must first account for the conditional error and correlated design contribution or refactor a suitable joint whitening transformation. This is a measurement-model limitation, even when the rotations themselves remain perfectly orthogonal.

Repeated readings of a common reference are one practical source of precisely this kind of dependence.

Change parameters · Explore the worked calculation

Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.

Study the full derivation

Refitting a sensor as observations arrive or disappear · Matrix computations and spectral accuracy

A calibration line receives one new observation at a time. Update its least-squares factorisation using rotations, quantify the influence of a deleted observation and detect when removing a sample destroys identifiability.