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 (3045)\text{QR decomposition of } \begin{pmatrix} 3 & 0 \\ 4 & 5 \end{pmatrix}

Q=(35−454535),  R=(5403)\displaystyle Q = \begin{pmatrix} \frac{3}{5} & -\frac{4}{5} \\ \frac{4}{5} & \frac{3}{5} \end{pmatrix},\ \ R = \begin{pmatrix} 5 & 4 \\ 0 & 3 \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=(3,4)\mathbf{e}_{1} = \left(3, 4\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=(0,5)−(45)(3,4)=(−125,95)\begin{aligned} \mathbf{e}_{2} &= \left(0, 5\right) - \left(\frac{4}{5}\right)\left(3, 4\right) \\ &= \left(-\frac{12}{5}, \frac{9}{5}\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=125(3,4)=(35,45),  q2=19(−125,95)=(−45,35)\mathbf{q}_{1} = \frac{1}{\sqrt{25}}\left(3, 4\right) = \left(\frac{3}{5}, \frac{4}{5}\right),\ \ \mathbf{q}_{2} = \frac{1}{\sqrt{9}}\left(-\frac{12}{5}, \frac{9}{5}\right) = \left(-\frac{4}{5}, \frac{3}{5}\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=(5403)R = \begin{pmatrix} 5 & 4 \\ 0 & 3 \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=(35−454535),  R=(5403)Q = \begin{pmatrix} \frac{3}{5} & -\frac{4}{5} \\ \frac{4}{5} & \frac{3}{5} \end{pmatrix},\ \ R = \begin{pmatrix} 5 & 4 \\ 0 & 3 \end{pmatrix}
  6. Result

    So A=QRA = QR with Q=(35−454535),  R=(5403)Q = \begin{pmatrix} \frac{3}{5} & -\frac{4}{5} \\ \frac{4}{5} & \frac{3}{5} \end{pmatrix},\ \ R = \begin{pmatrix} 5 & 4 \\ 0 & 3 \end{pmatrix}.

Worked examples