Trying to find QR decomposition of a matrix.

3.7k Views Asked by At

Let $A=\begin{pmatrix}2&1\\2&0\\1&1\end{pmatrix}$ find $Q$ and $R$ such that $A=QR$.

First I tried to find $Im(A)=\{(a,b,c)\in\mathbb{R}^3|Ax=(a,b,c)compatible\}.$

so then solving a system we get: $Im(A)=Sp\{(1,0,1),(0,2,-1)\}$ after that i orthogonalized all this using Gram-Schmidt algorithm obtaining: $Sp\{(1,0,1),(3,1,2)\}$ orthogonal base. So then I thought $Q$ will be the matrix formed by vectors from the orthogonal base on columns, but it's not that... What am I doing wrong?

3

There are 3 best solutions below

0
On BEST ANSWER

I'm not certain where you went wrong because I can't see your work.

Suppose that $A$ is given by

$$ A = \begin{bmatrix} 2 & 1 \\ 2 & 0 \\ 1 & 1 \end{bmatrix} \tag{1} $$

find $A = QR$

In Gram-Schmidt you successfully take columns $v_{i}$ and normalize them

$$ v_{1} = a_{1} = \begin{bmatrix}2 & 2 & 1 \end{bmatrix} \tag{2} $$

e.g $ q_{1} = \frac{v_{1}}{\|v_{1}\|}$

$$ q_{1} = \frac{v_{1}}{\|v_{1} \|} = \frac{1}{\sqrt{9}}\begin{bmatrix}2 & 2 & 1 \end{bmatrix} =\begin{bmatrix}\frac{2}{3} & \frac{2}{3} & \frac{1}{3} \end{bmatrix}\tag{3} $$

then we subtract off our orthonormal vector $q_{1}$ from $a_{2}$ using a coefficient $(a_{2} \cdot q_{1})$. This happens to be $ r_{12}$ $$ v_{2} = a_{2} - (a_{2} \cdot q_{1})q_{1} = \begin{bmatrix} 1 & 0 & 1 \end{bmatrix} - 1 \cdot \begin{bmatrix}\frac{2}{3} & \frac{2}{3} & \frac{1}{3} \end{bmatrix} = \begin{bmatrix}\frac{1}{3} & \frac{-2}{3} & \frac{2}{3} \end{bmatrix} \tag{4} $$

we then normalize our new vector generating $q_{2}$

$$ q_{2} = \frac{v_{2}}{\|v_{2}\|} \tag{5}$$

$$ \| v_{2}\| = \sqrt{(\frac{1}{3})^{2} +(\frac{-2}{3})^{2} + (\frac{2}{3})^{2}} =1 \tag{6}$$

$$ Q = \begin{bmatrix} \frac{2}{3} & \frac{1}{3} \\ \frac{2}{3} & \frac{-2}{3} \\ \frac{1}{3} & \frac{2}{3} \end{bmatrix} = \frac{1}{3} \begin{bmatrix} 2 & 1 \\ 2 & -2\\ 1 & 2 \end{bmatrix} \tag{7} $$

then the matrix $R$ is given by the inner products of the orthogonal components and the vectors of the original matrix.

$$ R = \begin{bmatrix} a_{1} \cdot q_{1} & a_{2} \cdot q_{1} \\0 & a_{2} \cdot q_{2}\end{bmatrix} = \begin{bmatrix} r_{11} & r_{12} \\ 0 & r_{22} \end{bmatrix} = \begin{bmatrix} 3 & 1 \\ 0 & 1 \end{bmatrix} \tag{8} $$

this is confirmed here with some python

import numpy as np

A = np.matrix([[2,1],[2,0],[1,1]])
Q,R= np.linalg.qr(A)

Q
Out[2]: 
matrix([[-0.66666667,  0.33333333],
        [-0.66666667, -0.66666667],
        [-0.33333333,  0.66666667]])

R
Out[3]: 
matrix([[-3., -1.],
        [ 0.,  1.]])

It isn't unique so python may give something close to it.

0
On

I have three remarks.

(1) The image $\mathrm{Im}(A)$ is always spanned by the columns. Since the columns $a_1$ and $a_2$ are linearly independent, you can just say $\mathrm{Im}(A)=\mathrm{Sp}\{a_1,a_2\}=\mathrm{Sp}\{(2,2,1), (1,0,1)\}$.

(2) The vectors $(1,0,1)$ and $(3,1,2)$ you obtained are not orthogonal, so I guess you made a mistake in the Gram-Schmidt algorithm.

Applying the Gram-Schmidt algorithm to the basis $\{(2,2,1), (1,0,1)\}$ will give you $\{(2,2,1), \tfrac{1}{3}\left(1,-2,2\right)\}$

(3) By using the Gram-Schmidt you indeed should obtain an orthogonal basis of $\mathrm{Im}(A)$, but you should normalize these basis vectors, so that you obtain an orthonormal basis of $\mathrm{Im}(A)$. Putting these orthonormal vectors in a matrix give $$ Q = \frac{1}{3} \begin{bmatrix} 2 & 1 \\ 2 & -2 \\ 1 & 2 \\ \end{bmatrix} $$ In order to find $R$, note that $R = Q^T A.$

0
On

Consider $$ \alpha_{12}= \frac{1}{9} \begin{bmatrix} 2 & 2 & 1 \end{bmatrix} \begin{bmatrix} 1 \\ 0 \\ 1 \end{bmatrix}=\frac{1}{3} $$ Then you know that, up to normalization, the orthogonal basis is formed by the first column and $$ \begin{bmatrix} 1 \\ 0 \\ 1 \end{bmatrix} - \alpha_{12}\begin{bmatrix} 2 \\ 2 \\ 1 \end{bmatrix}= \begin{bmatrix} 1/3 \\ -2/3 \\ 2/3 \end{bmatrix} $$ which has norm $1$. You also know that $$ \begin{bmatrix} 2 & 1 \\ 2 & 0 \\ 1 & 1 \end{bmatrix} = \begin{bmatrix} 2 & 1/3 \\ 2 & -2/3 \\ 1 & 2/3 \end{bmatrix} \begin{bmatrix} 1 & \alpha_{12} \\ 0 & 1 \end{bmatrix} $$ Divide the first column by $3$ (its norm) and multiply the second matrix by the same factor $3$, getting $$ Q=\begin{bmatrix} 2/3 & 1/3 \\ 2/3 & -2/3 \\ 1/3 & 2/3 \end{bmatrix} \qquad R=\begin{bmatrix} 3 & 1 \\ 0 & 1 \end{bmatrix} $$