A mirror can swing an arrow onto an axis without changing its length. Watch a mirror turn until the arrow lands.
A mirror that clears a column
The arrow (3, 4) and a turning mirror through the origin.
The arrow (3, 4), of length 5, and a mirror along the horizontal axis. Its image is (3, −4).
Describe this picture
The plane with the arrow , of length 5, and a dashed circle of radius 5. A dotted mirror line through the origin starts along the horizontal axis and, after a short rest, turns slowly anticlockwise over 4 s. The arrow’s mirror image is drawn as it turns; its tip runs round the circle. When the mirror lies along , at 26.57° (0.4636 radians), the image lands on the horizontal axis at , and the picture holds there with the mirror’s matrix shown in the corner. When the clip has finished, the mirror can be turned by a ring on its line, dragged or moved with the arrow keys a degree at a time; it snaps onto 26.57° when it comes within 1.5°. Readouts give the angle and the image’s coordinates.
Gram–Schmidt, written down
Orthonormal bases and Gram–Schmidt turned the columns of
into three perpendicular unit arrows, , and . On the way it worked out some numbers and then threw them away: the shadows it took off, and the lengths it divided by. Keep them.
Run Gram–Schmidt backwards. Each column of is its leftover plus its shadows, and its leftover is a length times a . So
where is a shadow for , and is the length of the -th leftover. Column uses only to . In matrices,
with the ‘s as the columns of and the numbers in an upper triangle . This is the QR factorisation. On this page and mean these two factors; the bold of the signal processing pages, a correlation matrix, is a different thing.
For our :
Watch the matrices rebuild .
Cells
A = QR: perpendicular unit columns times an upper triangle.
A, with columns (1, 1, 0), (1, 0, 1), (0, 1, 1).
Describe this picture
Grids of cells in a row (two rows of two on a phone), each cell shaded by its number: , then with its three unit columns, , and , then the upper triangle with diagonal , , and faded zeros below it. A fourth grid then fills cell by cell with the product , the cell being filled outlined, and when it is full its label reads . The caption ends with a note: the signs on the diagonal of are a convention, and flipping a column of and the matching row of gives another correct pair. The picture has no control.
Looking ahead to The determinant as area: the diagonal of multiplies to , which is the size of . keeps volumes, so the triangle carries all of the volume.
Least squares with QR
In Least squares we solved . Put into it. Since , the left side is and the right side is . Cancel :
is a triangle, so this is one back substitution.
Try it on the line fit of that page, with columns and and heights . Gram–Schmidt gives with . The shadow of on is , which leaves , of length , so . Then , and back substitution gives
The same line, .
Why bother, when the normal equations gave the same answer? Because squares the difficulty. When two columns are nearly parallel, small rounding errors in become large errors in . Here is an extreme case. Take a tiny number and
whose exact answer is . The matrix has on its diagonal, and a computer working to about 16 digits rounds to exactly 1. It stores , which has no inverse, and the normal equations fail. QR never forms , and it returns .
Mirrors that clear a column
Programs rarely run Gram–Schmidt itself; rounding errors slowly spoil the right angles. They use mirrors. The picture at the top of the page is one step.
A mirror is a reflection across a line, an orthogonal matrix from the Gram–Schmidt page, so it keeps lengths. Choose the mirror that sends the first column onto the first axis. The column has length 5, so the mirror must send it to . The mirror line lies halfway between the two, along . Its matrix, called a Householder reflection, is
where is at a right angle to the mirror line. Here , and . Check: . This is local to this page; signal processing pages use bold for a filter’s matrix.
Apply the mirror to a whole matrix whose first column is :
The first column is cleared below the top. The result is upper triangular, so it is . Reflecting twice brings you back, , so with . Larger matrices use one mirror per column. The diagonal again carries the area: , and .
Here is negative. That is only a convention: a mirror that sends to works equally well. Programs choose the sign that keeps large, , here . The other choice subtracts two nearly equal numbers when the column is close to the axis. For , , and keeps only the last few digits of the two numbers.
Worked example
- From Gram–Schmidt. The matrix above has with diagonal , , , whose product is 2.
- A line fit. , , so and .
- Already orthonormal. If the columns of are already orthonormal, and .
- A mirror. sends to , and .
- Determinant from R. The size of is the product of the sizes of the diagonal of : 17 for the mirror example.
- Predict. As two columns become nearly parallel, the second leftover of Gram–Schmidt shrinks, so falls towards 0. That small number is the warning sign that Conditioning measures.
Where you’ll meet this
Library routines for least squares, such as NumPy’s lstsq, factor with orthogonal matrices instead of forming . For a tall matrix, Householder QR costs about twice as much as the normal equations, and buys back the accuracy that squaring would lose. Statistics software fits regression lines this way. Some Kalman filters carry a triangular factor like in place of a covariance matrix, for the same reason.
In signal processing · squared condition numbers
In Adaptive filters: LMS, the spread of the eigenvalues of the correlation matrix is its condition number, and it decides how slowly the filter learns. That correlation matrix is built like from the input samples, so it carries the square of the data’s own difficulty, the effect this page avoids.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Factorisation | , upper triangular | |
| Entries of | for ; = length of a leftover | Gram–Schmidt, written down |
| Least squares | back substitution | |
| Normal equations | they square the difficulty | |
| Householder | a mirror; | |
| Clearing a column | pick the sign that keeps large | |
| Determinant | square |