Skip to main content
Mathematics LibreTexts

14.5: QR Decomposition

  • Page ID
    2089
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)

    In chapter 7, section 7.7 we learned how to solve linear systems by decomposing a matrix \(M\) into a product of lower and upper triangular matrices

    \[M=LU\, .\]

    The Gram-Schmidt procedure suggests another matrix decomposition,

    \[M=QR\, ,\]

    where \(Q\) is an orthogonal matrix and \(R\) is an upper triangular matrix. So-called QR-decompositions are useful for solving linear systems, eigenvalue problems and least squares approximations. You can easily get the idea behind the \(QR\) decomposition by working through a simple example.

    Example \(\PageIndex{1}\):

    Find the \(QR\) decomposition of

    \[M=\begin{pmatrix}2&-1&1\\1&3&-2\\0&1&-2\end{pmatrix}\, .\]

    What we will do is to think of the columns of \(M\) as three 3-vectors and use Gram-Schmidt to build an orthonormal basis from these that will become the columns of the orthogonal matrix \(Q\). We will use the matrix \(R\) to record the steps of the Gram-Schmidt procedure in such a way that the product \(QR\) equals \(M\).

    To begin with we write

    \[
    M=\begin{pmatrix}2&-\frac{7}{5}&1\\1&\frac{14}{5}&-2\\0&1&-2\end{pmatrix}
    \begin{pmatrix}1&\frac{1}{5}&0\\0&1&0\\0&0&1\end{pmatrix}\, .
    \]

    In the first matrix the first two columns are orthogonal because we simply replaced the second column of \(M\) by the vector that the Gram-Schmidt procedure produces from the first two columns of \(M\), namely

    \[
    \begin{pmatrix}-\frac{7}{5}\\\frac{14}{5}\\1\end{pmatrix}=\begin{pmatrix}-1\\3\\1\end{pmatrix}-\frac{1}{5}
    \begin{pmatrix} 2 \\1\\0\end{pmatrix}\, .
    \]

    The matrix on the right is almost the identity matrix, save the \(+\frac{1}{5}\) in the second entry of the first row, whose effect upon multiplying the two matrices precisely undoes what we we did to the second column of the first matrix. For the third column of \(M\) we use Gram--Schmidt to deduce the third orthogonal vector

    \[\begin{pmatrix}-\frac{1}{6}\\\frac{1}{3}\\-\frac{7}{6}\end{pmatrix}=\begin{pmatrix}1\\-2\\-2\end{pmatrix}-0\begin{pmatrix}2\\1\\0\end{pmatrix}-\frac{-9}{\frac{54}{5}}\begin{pmatrix}-\frac{7}{5}\\\frac{14}{5}\\1\end{pmatrix}\, \]

    and therefore, using exactly the same procedure write

    \[
    M=\begin{pmatrix}2&-\frac{7}{5}&-\frac{1}{6}\\1&\frac{14}{5}&\frac{1}{3}\\0&1&-\frac{7}{6}\end{pmatrix}
    \begin{pmatrix}1&\frac{1}{5}&0\\0&1&-\frac{5}{6}\\0&0&1\end{pmatrix}\, .
    \]

    This is not quite the answer because the first matrix is now made of mutually orthogonal column vectors, but a \(\textit{bona fide}\) orthogonal matrix is comprised of orthonormal vectors. To achieve that we divide each column of the first matrix by its length and multiply the corresponding row of the second matrix by the same amount:

    \[
    M=\begin{pmatrix}\frac{2\sqrt{5}}{5}&-\frac{7\sqrt{30}}{90}&-\frac{\sqrt{6}}{18}\\
    \frac{\sqrt{5}}{5}&\frac{7\sqrt{30}}{45}&\frac{\sqrt{6}}{9}\\
    0&\frac{\sqrt{30}}{18}&-\frac{7\sqrt{6}}{18}\end{pmatrix}
    \begin{pmatrix}\sqrt{5}&\frac{\sqrt{5}}{5}&0\\
    0&\frac{3\sqrt{30}}{5}&-\frac{\sqrt{30}}{2}\\
    0&0&\frac{\sqrt{6}}{2}\end{pmatrix}=QR\, .
    \]

    A nice check of this result is to verify that entry \((i,j)\) of the matrix \(R\) equals the dot product of the \(i\)-th column of \(Q\) with the \(j\)-th column of \(M\). (Some people memorize this fact and use it as a recipe for computing \(QR\) deompositions.) \(\textit{A good test of your own understanding is to work out why this is true!}\)

    Contributor

    This page titled 14.5: QR Decomposition is shared under a not declared license and was authored, remixed, and/or curated by David Cherney, Tom Denton, & Andrew Waldron.