QR Decomposition Calculator

Enter a matrix with independent columns to factor it as QR.

Matrix A
Rows
2
Columns
2

A matrix whose columns are independent, rows separated by semicolons.

Try

Result

You enteredQR decomposition of (1101)\text{QR decomposition of } \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix}

Q=(1001),  R=(1101)\displaystyle Q = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix},\ \ R = \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix}
Show the work
  1. Start with the first vector

    The first column needs no change: e1=a1\mathbf{e}_1 = \mathbf{a}_1. Every later one is made at right angles to it.

    e1=(1,0)\mathbf{e}_{1} = \left(1, 0\right)
  2. Remove the directions already used

    Subtract from a2\mathbf{a}_{2} its projection onto each earlier ei\mathbf{e}_i. What is left, e2\mathbf{e}_{2}, is at right angles to all of them.

    Using ek=ak−∑i<kak⋅eiei⋅eiei\mathbf{e}_k = \mathbf{a}_k - \sum_{i<k} \frac{\mathbf{a}_k \cdot \mathbf{e}_i}{\mathbf{e}_i \cdot \mathbf{e}_i}\mathbf{e}_i

    e2=(1,1)−1(1,0)=(0,1)\begin{aligned} \mathbf{e}_{2} &= \left(1, 1\right) - 1\left(1, 0\right) \\ &= \left(0, 1\right) \end{aligned}
  3. Normalise to length 1

    Divide each ek\mathbf{e}_k by its own length to get a vector of length 1 pointing the same way. The results qk\mathbf{q}_k are orthonormal: unit length and at right angles to each other.

    Using qk=ek∣ek∣\mathbf{q}_k = \frac{\mathbf{e}_k}{\left|\mathbf{e}_k\right|}

    q1=11(1,0)=(1,0),  q2=11(0,1)=(0,1)\mathbf{q}_{1} = \frac{1}{\sqrt{1}}\left(1, 0\right) = \left(1, 0\right),\ \ \mathbf{q}_{2} = \frac{1}{\sqrt{1}}\left(0, 1\right) = \left(0, 1\right)
  4. The matrix R

    Each column aj\mathbf{a}_j is a combination of the orthonormal vectors, and the coefficients are dot products: rij=qi⋅ajr_{ij} = \mathbf{q}_i \cdot \mathbf{a}_j above the diagonal and rii=∣ei∣r_{ii} = \left|\mathbf{e}_i\right| on it. Below the diagonal the entries are 0, so RR is upper triangular.

    R=(1101)R = \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix}
  5. QR decomposition

    The orthonormal vectors are the columns of QQ, so QQ has QTQ=IQ^{\mathsf{T}}Q = I, and multiplying QQ by RR rebuilds AA.

    Using A=QRA = Q R

    Q=(1001),  R=(1101)Q = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix},\ \ R = \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix}
  6. Result

    So A=QRA = QR with Q=(1001),  R=(1101)Q = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix},\ \ R = \begin{pmatrix} 1 & 1 \\ 0 & 1 \end{pmatrix}.

Worked examples