How this instrument works
QR decomposition splits a matrix into two pieces: Q, an orthogonal matrix whose columns are all perpendicular to each other and each exactly length 1, and R, an upper-triangular matrix recording how the original columns relate to those new perpendicular directions. Multiplying Q by R exactly reconstructs the original matrix.
The Gram-Schmidt process builds Q one column at a time: the first column of Q is simply the original first column, rescaled to length 1. The second column of Q is what remains of the original second column AFTER removing whatever part of it points along that first direction — the amount removed (the projection) becomes an entry in R, and what's left over, rescaled to length 1, becomes Q's second column.
R's diagonal entries carry a direct geometric meaning: r₁₁ is the original first column's own length, and r₂₂ is the LENGTH REMAINING in the second column after its shared direction with the first has been projected out and subtracted away.
- Enter the matrix's four entries into the a, b, c, and d fields (columns (a,c) and (b,d)).
- Read r₁₁: the first column's own length.
- Read r₁₂: how much of the second column points along the first column's direction.
- Read r₂₂: the length remaining in the second column once that shared direction is removed.
Worked example — [[1,1],[0,1]]
For [[1,1],[0,1]] (columns (1,0) and (1,1)): the first column, (1,0), already has length 1, so r₁₁=1. The second column, (1,1), projects onto that first direction by r₁₂=(1×1+0×1)⁄1=1, and what's left after removing that projection has length r₂₂=√(2−1)=1 — Q here turns out to be the identity matrix, since the first column was already a unit vector along the x-axis.
For [[3,0],[4,5]] (columns (3,4) and (0,5)): the first column, (3,4), has length 5 (a 3-4-5 triangle), the projection r₁₂ is (3×0+4×5)⁄5=4, and the remaining length is r₂₂=√(25−16)=3. For a diagonal matrix [[2,0],[0,2]], the columns are already perpendicular, so r₁₂ comes out to exactly 0, with r₁₁ and r₂₂ simply the diagonal entries themselves.
Questions
What is QR decomposition used for?
Splitting a matrix into a perpendicular-direction piece (Q) and a triangular piece (R) that records how the original columns relate to those directions — a building block for solving least-squares problems and for finding eigenvalues numerically.
What does R's diagonal represent?
r₁₁ is the first column's own length, and r₂₂ is how much length remains in the second column once its shared direction with the first has been projected out — together, they capture the 'independent size' each column contributes.
What is the Gram-Schmidt process?
A method for building a set of perpendicular directions one at a time from an original set of columns — each new direction is what remains of the next original column once its overlap with all the previous directions has been removed.
What if the two columns already point in perpendicular directions?
Then the projection, r₁₂, comes out to exactly 0 — there's no shared direction to remove, and r₁₁ and r₂₂ simply become each column's own length directly.
Why can't the first column be all zeros?
It needs an actual direction to normalize into a unit vector — a zero column has no direction at all, so the whole Gram-Schmidt process has nothing to build the first perpendicular direction from.