4.3 Orthogonal Matrices and the QR Factorization A new matrix factorization
Dept. of Electrical and Systems Engineering
University of Pennsylvania
1 Reading ¶ Material related to this page, as well as additional exercises, can be found in ALA 4.3.
2 Learning Objectives ¶ By the end of this page, you should know:
an orthogonal matrix the QR factorization of a square matrix how to use the QR factorization to solve systems of equatitons of the form A x = b A\vv{x} = \vv b A x = b , with A A A square 3 Orthogonal Matrices ¶ Rotations and reflections play key roles in geometry, physics, robotics, quantum mechanics, airplanes, compute graphics, data science, and more. These transformations are encoded via orthogonal matrices , that is matirces whose columns form an orthonormal basis for R n \mathbb{R}^n R n . They also play a central role in one of the most important methods of linear algebra, the QR factorization .
We start with a definition.
Definition 1 (Orthogonal Matrix)
A square matrix Q Q Q is called orthogonal if it satisfies
Q Q ⊤ = Q ⊤ Q = I . \begin{align*}
QQ^{\top} = Q^{\top}Q = I.
\end{align*} Q Q ⊤ = Q ⊤ Q = I . This means that Q − 1 = Q ⊤ Q^{-1} = Q^{\top} Q − 1 = Q ⊤ (in fact, we could define orthogonal matrices this way instead), and that solving linear systems of the form Q x = b Q\vv x = \vv b Q x = b is very easy: simply set x = Q ⊤ b \vv x = Q^\top \vv b x = Q ⊤ b !
Notice that Q ⊤ Q = I Q^\top Q = I Q ⊤ Q = I implies that the columns of Q Q Q are orthonormal. If Q = [ q 1 , . . . , q n ] Q = [\vv{q_1}, ..., \vv{q_n}] Q = [ q 1 , ... , q n ] , then
( Q ⊤ Q ) i j = q i ⊤ q j = I i j = { 1 if i ≠ j 0 if i = j \begin{align*}
(Q^\top Q)_{ij} = \vv{q_i}^\top \vv{q_j} = I_{ij} = \begin{cases} 1 \quad\text{if $i \neq j$}\\ 0\quad\text{if $i = j$}\end{cases}
\end{align*} ( Q ⊤ Q ) ij = q i ⊤ q j = I ij = { 1 if i = j 0 if i = j which is exactly the definition of an orthonormal collcetion of vectors. Further, since ther eare n n n such vectors, they must form an orthonormal basis for R n \mathbb{R}^n R n .
Now, let’s explore some of the consequences of this definition.
Example 1 (
2 × 2 2 \times 2 2 × 2 orthogonal matrices)
A 2 × 2 2\times 2 2 × 2 matric Q = [ a b c d ] Q = \bm a&b\\c&d\em Q = [ a c b d ] is orthogonal if and only if
Q ⊤ Q = [ a 2 + c 2 a b + c d a c + c d b 2 + d 2 ] = [ 1 0 0 1 ] \begin{align*}
Q^\top Q = \bm a^2 + c^2 & ab + cd \\ ac + cd & b^2 + d^2\em = \bm 1& 0\\ 0& 1\em
\end{align*} Q ⊤ Q = [ a 2 + c 2 a c + c d ab + c d b 2 + d 2 ] = [ 1 0 0 1 ] or equivalently
a 2 + c 2 = 1 , a b + c d = 0 , b 2 + d 2 = 1 \begin{align*}
a^2 + c^2 = 1, \quad ab + cd = 0, \quad b^2 + d^2 = 1
\end{align*} a 2 + c 2 = 1 , ab + c d = 0 , b 2 + d 2 = 1 The first and last equations say that [ a c ] \bm a\\ c \em [ a c ] and [ b d ] \bm b\\ d \em [ b d ] lie on the unit circle in R 2 \mathbb{R}^2 R 2 : a convenient and revealing way of writing this is by setting
a = cos θ , c = sin θ , b = cos ϕ , d = sin ϕ \begin{align*}
a = \cos \theta, \quad c= \sin \theta, \quad b = \cos \phi, \quad d = \sin \phi
\end{align*} a = cos θ , c = sin θ , b = cos ϕ , d = sin ϕ since cos 2 θ + sin 2 θ = 1 \cos^2 \theta + \sin^2\theta = 1 cos 2 θ + sin 2 θ = 1 for all θ ∈ R \theta \in \mathbb{R} θ ∈ R .
Our last condition is 0 = a d + c d = cos θ cos ϕ + sin θ sin ϕ = cos ( θ − ϕ ) 0 = ad + cd = \cos\theta \cos \phi +\sin\theta \sin\phi = \cos(\theta - \phi) 0 = a d + c d = cos θ cos ϕ + sin θ sin ϕ = cos ( θ − ϕ ) . Now
cos ( θ − ϕ ) = 0 ⟺ θ − ϕ = π 2 + 2 n π or θ − ϕ = − π 2 ⟺ π = θ ± π 2 \begin{align*}
\cos (\theta - \phi) = 0 &\iff \theta - \phi = \frac{\pi}{2} + 2 n \pi\quad \text{or} \quad \theta - \phi = -\frac{\pi}{2} \\
&\iff \pi = \theta \pm \frac{\pi}{2}
\end{align*} cos ( θ − ϕ ) = 0 ⟺ θ − ϕ = 2 π + 2 nπ or θ − ϕ = − 2 π ⟺ π = θ ± 2 π This means either:
As a result, every 2 × 2 2\times 2 2 × 2 orthogonal matrix has one of two possible forms:
[ cos θ − sin θ sin θ cos θ ] or [ cos θ sin θ sin θ − cos θ ] \begin{align*}
\bm \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \em \quad\text{or}\quad \bm \cos\theta & \sin\theta \\ \sin\theta & -\cos\theta \em
\end{align*} [ cos θ sin θ − sin θ cos θ ] or [ cos θ sin θ sin θ − cos θ ] where by convention, we restrict θ ∈ [ 0 , 2 π ) \theta \in [0, 2\pi) θ ∈ [ 0 , 2 π ) .
The columns of both matrices form an orthonormal basis for R 2 \mathbb{R}^2 R 2 . The first is obtained by rotating the standard basis e 1 , e 2 \vv{e_1}, \vv{e_2} e 1 , e 2 through angle θ, the second by first reflexting about the x-axis and the rotating.
If we think about the map x ↦ Q x \vv x \mapsto Q \vv x x ↦ Q x defined by multiplication with an orthogonal matrix as rotating and/or reflectingthe vector x \vv x x , then the following property should not be surprising:
Before grinding through some algebra, let’s think about this through the lens of rotation and reflections. Multiply x \vv x x by a product of orthogonal matrices Q 2 Q 1 Q_2Q_1 Q 2 Q 1 is the same as first rotation/reflecting x \vv x x by Q 1 Q_1 Q 1 to obtain Q 1 x Q_1 \vv x Q 1 x , and then rotating/reflecting Q 1 x Q_1 \vv x Q 1 x by Q 2 Q_2 Q 2 to get Q 2 Q 1 x Q_2 Q_1 \vv x Q 2 Q 1 x . Now a sequence of rotations and reflections is still ultimately a rotation and/or reflection so we must have Q 2 Q 1 x = Q x Q_2 Q_1 \vv x = Q \vv x Q 2 Q 1 x = Q x for some orthogonal Q = Q 2 Q 1 Q = Q_2 Q_1 Q = Q 2 Q 1 .
Let’s check that this intuition carries over in the math. Since Q 1 Q_1 Q 1 and Q 2 Q_2 Q 2 are orthogonal, we have that
Q 1 ⊤ Q 1 = I = Q 2 ⊤ Q 2 . \begin{align*}
Q^\top_1 Q_1 = I = Q_2^\top Q_2.
\end{align*} Q 1 ⊤ Q 1 = I = Q 2 ⊤ Q 2 . Let’s check that ( Q 1 Q 2 ) ⊤ ( Q 1 Q 2 ) = I (Q_1Q_2)^\top (Q_1Q_2) = I ( Q 1 Q 2 ) ⊤ ( Q 1 Q 2 ) = I :
( Q 1 Q 2 ) ⊤ ( Q 1 Q 2 ) = Q 2 ⊤ Q 1 ⊤ Q 1 ⏟ I Q 2 = Q 2 ⊤ Q 2 ⏟ I = I \begin{align*}
(Q_1Q_2)^\top (Q_1Q_2) = Q_2^\top \underbrace{Q_1^\top Q_1}_{I}Q_2 = \underbrace{Q_2^\top Q_2}_I = I
\end{align*} ( Q 1 Q 2 ) ⊤ ( Q 1 Q 2 ) = Q 2 ⊤ I Q 1 ⊤ Q 1 Q 2 = I Q 2 ⊤ Q 2 = I Therefore ( Q 1 Q 2 ) − 1 = ( Q 1 Q 2 ) ⊤ (Q_1 Q_2)^{-1} = (Q_1 Q_2)^\top ( Q 1 Q 2 ) − 1 = ( Q 1 Q 2 ) ⊤ , and we indeed have Q 1 Q 2 Q_1Q_2 Q 1 Q 2 is orthogonal.
This multiplicative property combined with the fact that the inverse of an orthogonal matrix is orthogonal (why?) says that the set of all orthogonal matrices (of dimension n n n ) forms a group (under matrix multiplication).
Group theory underlies much of modern physics and quantum mechanics and plays a central role in robotics. Although we will not spend too much time on groups in this class, you are sure to see them again in the future.
The aforementioned orthogonal group in particular is central to rigid body mechanics, atomic structure and chemistry, and computer graphics, among many other applications.
4 The QR Factorization ¶ The GSP , when applied to orthonormalize a basis of R n \mathbb{R}^n R n , in fact gives us the famous, incredibly useful QR factorization of a matrix:
Let us start with a basis b 1 , . . . , b n \vv{b_1}, ..., \vv{b_n} b 1 , ... , b n for R n \mathbb{R}^n R n , and let u 1 , . . . , u n \vv{u_1}, ..., \vv{u_n} u 1 , ... , u n be the result of applying the GSP to it. Define the matrices:
A = [ b 1 b 2 . . . b n ] , Q = [ u 1 u 2 . . . u n ] . \begin{align*}
A = \bm \vv{b_1} & \vv{b_2} & ... & \vv{b_n} \em, \quad Q = \bm \vv{u_1} & \vv{u_2} & ... & \vv{u_n} \em.
\end{align*} A = [ b 1 b 2 ... b n ] , Q = [ u 1 u 2 ... u n ] . Q Q Q is an orthogonal matrix because the u i \vv{u_i} u i form an orthonormal basis.
Now, let’s revisit the GSP equations:
v 1 = b 1 v 2 = b 2 − ⟨ b 2 , v 1 ⟩ ⟨ v 1 , v 1 ⟩ v 1 v 3 = b 3 − ⟨ b 3 , v 1 ⟩ ⟨ v 1 , v 1 ⟩ v 1 − ⟨ b 3 , v 2 ⟩ ⟨ v 2 , v 2 ⟩ v 2 ⋮ v n = b n − ⟨ b n , v 1 ⟩ ⟨ v 1 , v 1 ⟩ v 1 − . . . − ⟨ b n , v n − 1 ⟩ ⟨ v n − 1 , v n − 1 ⟩ v n − 1 \begin{align*}
\vv{v_1} &= \vv{b_1} \\
\vv{v_2} &= \vv{b_2} - \frac{\langle \vv{b_2}, \vv{v_1} \rangle}{\langle \vv{v_1}, \vv{v_1} \rangle}\vv{v_1}\\
\vv{v_3} &= \vv{b_3} - \frac{\langle \vv{b_3}, \vv{v_1} \rangle}{\langle \vv{v_1}, \vv{v_1} \rangle}\vv{v_1} - \frac{\langle \vv{b_3}, \vv{v_2} \rangle}{\langle \vv{v_2}, \vv{v_2} \rangle}\vv{v_2}\\
\vdots\\
\vv{v_n} &= \vv{b_n} - \frac{\langle \vv{b_n}, \vv{v_1} \rangle}{\langle \vv{v_1}, \vv{v_1} \rangle}\vv{v_1} - ... - \frac{\langle \vv{b_n}, \vv{v_{n-1}} \rangle}{\langle \vv{v_{n-1}}, \vv{v_{n-1}} \rangle}\vv{v_{n-1}}\\
\end{align*} v 1 v 2 v 3 ⋮ v n = b 1 = b 2 − ⟨ v 1 , v 1 ⟩ ⟨ b 2 , v 1 ⟩ v 1 = b 3 − ⟨ v 1 , v 1 ⟩ ⟨ b 3 , v 1 ⟩ v 1 − ⟨ v 2 , v 2 ⟩ ⟨ b 3 , v 2 ⟩ v 2 = b n − ⟨ v 1 , v 1 ⟩ ⟨ b n , v 1 ⟩ v 1 − ... − ⟨ v n − 1 , v n − 1 ⟩ ⟨ b n , v n − 1 ⟩ v n − 1 We start by replacing each element v i \vv{v_i} v i with its normalized form, u i = v i ∥ v i ∥ \vv{u_i} = \frac{\vv{v_i}}{\| \vv{v_i} \|} u i = ∥ v i ∥ v i . Rearranging the above, we can write the original basis elements b i \vv{b_i} b i in terms of the orthonormal basis u i \vv{u_i} u i via the triangular system
b 1 = r 11 u 1 b 2 = r 12 u 1 + r 22 u 2 b 3 = r 13 u 1 + r 23 u 2 = r 33 u 3 ⋮ b n = r 1 n u 1 + r 2 n u 2 + . . . + r n n u n \begin{align*}
\vv{b_1} &= r_{11}\vv{u_1}\\
\vv{b_2} &= r_{12}\vv{u_1} + r_{22}\vv{u_2}\\
\vv{b_3} &= r_{13}\vv{u_1} + r_{23}\vv{u_2} = r_{33}\vv{u_3}\\
\vdots\\
\vv{b_n} &= r_{1n}\vv{u_1} + r_{2n}\vv{u_2} + ... + r_{nn}\vv{u_n}
\end{align*} b 1 b 2 b 3 ⋮ b n = r 11 u 1 = r 12 u 1 + r 22 u 2 = r 13 u 1 + r 23 u 2 = r 33 u 3 = r 1 n u 1 + r 2 n u 2 + ... + r nn u n Using our usual trick of taking inner products with both sides we see that
⟨ b j , u i ⟩ = ⟨ r 1 j u 1 + . . . + r j j u j , u i ⟩ = r 1 j ⟨ u 1 , u i ⟩ + . . . + r i j ⟨ u i , u i ⟩ + . . . + r j j ⟨ u i , u j ⟩ = r i j \begin{align*}
\langle \vv{b_j}, \vv{u_i}\rangle &= \langle r_{1j}\vv{u_1} + ... + r_{jj}\vv{u_j}, \vv{u_i}\rangle \\
&= r_{1j} \langle \vv{u_1}, \vv{u_i} \rangle + ... + r_{ij} \langle \vv{u_i}, \vv{u_i} \rangle + ... + r_{jj} \langle \vv{u_i}, \vv{u_j} \rangle \\
&= r_{ij}
\end{align*} ⟨ b j , u i ⟩ = ⟨ r 1 j u 1 + ... + r jj u j , u i ⟩ = r 1 j ⟨ u 1 , u i ⟩ + ... + r ij ⟨ u i , u i ⟩ + ... + r jj ⟨ u i , u j ⟩ = r ij So we conclude that r i j = ⟨ b j , u i ⟩ r_{ij} = \langle \vv{b_j}, \vv{u_i} \rangle r ij = ⟨ b j , u i ⟩ .
Now, returning to (13) , we observe that if we define the upper triangular matrix
R = [ r 11 r 12 … r 1 n 0 r 22 … r 2 n ⋮ ⋮ ⋱ ⋮ 0 0 … r n n ] \begin{align*}
R = \bm
r_{11} & r_{12} & \dots & r_{1n}\\
0 & r_{22} & \dots & r_{2n}\\
\vdots & \vdots & \ddots & \vdots\\
0 & 0 & \dots & r_{nn}
\em
\end{align*} R = ⎣ ⎡ r 11 0 ⋮ 0 r 12 r 22 ⋮ 0 … … ⋱ … r 1 n r 2 n ⋮ r nn ⎦ ⎤ we can write A = Q R A = QR A = QR . Since the GSP works on any basis, the only requirement for A A A to have a QR factorization is that its columns form a basis for R n \mathbb{R}^n R n , i.e., that A A A be nonsingular.
5 Pseudocode for the QR Factorization Algorithm ¶ We can condense the above process into an algorithm, for which we give pseudocode below. Note that this algorithm assumes that the underlying inner product is the dot prodcut, but it can easily be adapted to any inner product.
Algorithm 1 (QR Factorization)
Inputs An invertible n × n n \times n n × n matrix A A A (with entries a i j a_{ij} a ij )
Output Invertible n × n n \times n n × n matrices Q Q Q (with entries q i j q_{ij} q ij ) and R R R (with entries r i j r_{ij} r ij ) such that A = Q R A = QR A = QR , where Q Q Q is orthogonal and R R R is upper triangular
Q ← A Q \gets A Q ← A R ← R \gets R ← empty n × n n \times n n × n matrixfor j = 1 j=1 j = 1 to n n n :\quad r j j ← q 1 j 2 + ⋯ + q n j 2 r_{jj} \gets \sqrt{q_{1j}^2 + \dots + q_{nj}^2} r jj ← q 1 j 2 + ⋯ + q nj 2 \quad if r j j = 0 r_{jj} = 0 r jj = 0 , stop ; print “A has linearly dependent columns”\quad \quad else for i = 1 i = 1 i = 1 to n n n \quad \quad \quad q i j ← q i j / r j j q_{ij} \gets q_{ij} / r_{jj} q ij ← q ij / r jj \quad for k = j + 1 k = j + 1 k = j + 1 to n n n \quad \quad r j k ← q 1 j q 1 k + ⋯ + q n j q n k r_{jk} \gets q_{1j}q_{1k} + \dots + q_{nj}q_{nk} r jk ← q 1 j q 1 k + ⋯ + q nj q nk \quad \quad for i = 1 i = 1 i = 1 to n n n \quad \quad \quad q i k ← q i k − q i j r j k q_{ik} \gets q_{ik} - q_{ij}r_{jk} q ik ← q ik − q ij r jk return Q Q Q , R R R
At first glance, this algorithm might look a little different that the process we just outlined. However, it’s really the same idea, just the order of subtracting off components is different. Instead of visiting each basis vector and subtracting off the components parallel to vectors before it (which we did in the Gram-Schmidt Process ), we visit each basis vector and subtract the components parallel to it from every vector after it.
5.1 Python break! ¶ We give an implementation of Algorithm 1 in NumPy below, and run it on some test cases.
import numpy as np
def qr_factorization(A):
if (A.shape[0] != A.shape[1]):
print('A is not square')
return None, None
n = A.shape[0]
Q = A.copy()
R = np.zeros((n, n))
for j in range(n):
R[j, j] = np.linalg.norm(Q[:, j])
if R[j, j] < 1e-8:
print('A has linearly dependent columns')
return None, None
else:
for i in range(n):
Q[i, j] = Q[i, j] / R[j, j]
for k in range(j + 1, n):
R[j, k] = np.dot(Q[:, j], Q[:, k])
for i in range(n):
Q[i, k] = Q[i, k] - Q[i, j] * R[j, k]
return Q, R
print('Test case with invertible matrix:')
A = np.array([[2.0, 1.0, 3.0], [-1.0, 0.0, 1.0], [0.0, 2.0, -1.0]])
print('A:')
print(A)
print('Q:')
Q, R = qr_factorization(A)
print(Q)
print('R:')
print(R)
print('QR:')
print(np.round(Q @ R, 2))
print('(Q^T)Q:')
print(np.round(Q.T @ Q, 2))
print('\nTest case with noninvertible matrix:')
A = np.array([[2.0, 1.0, 3.0], [-1.0, 0.0, 1.0], [1.0, 1.0, 4.0]])
print('A:')
print(A)
Q, R = qr_factorization(A)
print('Q:')
print(Q)
print('R:')
print(R)
Test case with invertible matrix:
A:
[[ 2. 1. 3.]
[-1. 0. 1.]
[ 0. 2. -1.]]
Q:
[[ 0.89442719 0.09759001 0.43643578]
[-0.4472136 0.19518001 0.87287156]
[ 0. 0.97590007 -0.21821789]]
R:
[[ 2.23606798 0.89442719 2.23606798]
[ 0. 2.04939015 -0.48795004]
[ 0. 0. 2.40039679]]
QR:
[[ 2. 1. 3.]
[-1. -0. 1.]
[ 0. 2. -1.]]
(Q^T)Q:
[[ 1. 0. -0.]
[ 0. 1. -0.]
[-0. -0. 1.]]
Test case with noninvertible matrix:
A:
[[ 2. 1. 3.]
[-1. 0. 1.]
[ 1. 1. 4.]]
A has linearly dependent columns
Q:
None
R:
None
6 Solving linear systems with a QR factorization ¶ Solving linear systems using a QR factorization is easy. Observe that if our goal is to solve A x = b A\vv x = \vv b A x = b and a QR factorization is available we first notice that
Q R x = b ⟺ R x = Q T b = b ~ \begin{align*}
QR \vv x = \vv b \iff R \vv x = Q^T \vv b = \vv{\tilde b}
\end{align*} QR x = b ⟺ R x = Q T b = b ~ since Q ⊤ Q = I Q^\top Q = I Q ⊤ Q = I . Now, solving R x = b ~ R\vv x = \vv{\tilde b} R x = b ~ can be easily accomplished via backsubstitution since R R R is an upper triangular matrix!
Exercise 1 (Solving a linear system via QR factorization)
Using a QR factorization , factor the matrix
A = [ 1 3 2 1 ] \begin{align*}
A = \bm 1 & 3 \\ 2 & 1\em
\end{align*} A = [ 1 2 3 1 ] as A = Q R A = QR A = QR . Then, use the QR factorization of A A A to solve the linear system
A x = [ 8 1 ] \begin{align*}
A \vv x = \bm 8 \\ 1 \em
\end{align*} A x = [ 8 1 ] Denote the columns of A A A as
a 1 = [ 1 2 ] , a 2 = [ 3 1 ] \begin{align*}
\vv{a_1} = \bm 1\\ 2\em, \quad \vv{a_2} = \bm 3 \\ 1 \em
\end{align*} a 1 = [ 1 2 ] , a 2 = [ 3 1 ] First, we apply the Gram-Schmidt process to find an orthogonal basis for span ( a 1 , a 2 ) \text{span}(\vv{a_1}, \vv{a_2}) span ( a 1 , a 2 ) (the columnspace of A A A ). We that one such orthogonal basis is given by
v 1 = a 1 = [ 1 2 ] v 2 = a 2 − ⟨ a 2 , v 1 ⟩ ⟨ v 1 , v 1 ⟩ v 1 = [ 2 − 1 ] \begin{align*}
\vv{v_1} &= \vv{a_1} = \bm 1\\2 \em\\
\vv{v_2} &= \vv{a_2} - \frac{\langle \vv{a_2}, \vv{v_1} \rangle}{\langle \vv{v_1}, \vv{v_1} \rangle}\vv{v_1} = \bm 2\\ -1 \em
\end{align*} v 1 v 2 = a 1 = [ 1 2 ] = a 2 − ⟨ v 1 , v 1 ⟩ ⟨ a 2 , v 1 ⟩ v 1 = [ 2 − 1 ] And an orthonormal basis is given by
u 1 = [ 1 5 2 5 ] , u 2 = [ 2 5 − 1 5 ] \begin{align*}
\vv{u_1} = \bm \frac{1}{\sqrt 5}\\\frac{2}{\sqrt 5} \em, \quad\vv{u_2} = \bm \frac{2}{\sqrt 5}\\-\frac{1}{\sqrt 5} \em
\end{align*} u 1 = [ 5 1 5 2 ] , u 2 = [ 5 2 − 5 1 ] So we have that our Q Q Q matrix is given by
Q = [ 1 5 2 5 2 5 − 1 5 ] \begin{align*}
Q = \boxed{\bm \frac{1}{\sqrt 5} & \frac{2}{\sqrt 5} \\ \frac{2}{\sqrt 5} & -\frac{1}{\sqrt 5} \em }
\end{align*} Q = [ 5 1 5 2 5 2 − 5 1 ] Now we compute the R R R matrix. Recall that
R = [ ⟨ u 1 , a 1 ⟩ ⟨ u 1 , a 2 ⟩ 0 ⟨ u 2 , a 2 ⟩ ] \begin{align*}
R = \bm \langle \vv{u_1}, \vv{a_1} \rangle &\langle \vv{u_1}, \vv{a_2} \rangle \\ 0 &\langle \vv{u_2}, \vv{a_2}\rangle \em
\end{align*} R = [ ⟨ u 1 , a 1 ⟩ 0 ⟨ u 1 , a 2 ⟩ ⟨ u 2 , a 2 ⟩ ] Substituting in values for u i \vv{u_i} u i and b j \vv{b_j} b j , we have that our R R R matrix is given by
R = [ 5 5 0 5 ] \begin{align*}
R = \boxed{\bm
\sqrt 5 & \sqrt 5 \\ 0 & \sqrt 5
\em }
\end{align*} R = [ 5 0 5 5 ] You can check that Q Q Q is orthogonal (Q ⊤ Q = I Q^\top Q = I Q ⊤ Q = I ), R R R is invertible upper triangular, and A = Q R A = QR A = QR .
Next, we solve A x = [ 8 1 ] A\vv x = \bm 8 \\ 1\em A x = [ 8 1 ] :
A x = [ 8 1 ] ⟺ Q R x = [ 8 1 ] ⟺ ( Q ⊤ Q ) ⏟ I R x = Q ⊤ [ 8 1 ] ⟺ [ 5 5 0 5 ] [ x 1 x 2 ] = [ 1 5 2 5 2 5 − 1 5 ] [ 8 1 ] = [ 2 5 3 5 ] \begin{align*}
A\vv x = \bm 8 \\ 1\em &\iff QR \vv x = \bm 8 \\ 1 \em\\
&\iff \underbrace{(Q^\top Q)}_I R \vv x = Q^\top \bm 8 \\ 1 \em\\
&\iff \bm \sqrt 5 & \sqrt 5 \\ 0 & \sqrt 5\em \bm x_1 \\ x_2\em = \bm \frac{1}{\sqrt 5} & \frac{2}{\sqrt 5} \\ \frac{2}{\sqrt 5} & -\frac{1}{\sqrt 5} \em\bm 8\\ 1\em = \bm 2\sqrt 5 \\ 3\sqrt 5 \em
\end{align*} A x = [ 8 1 ] ⟺ QR x = [ 8 1 ] ⟺ I ( Q ⊤ Q ) R x = Q ⊤ [ 8 1 ] ⟺ [ 5 0 5 5 ] [ x 1 x 2 ] = [ 5 1 5 2 5 2 − 5 1 ] [ 8 1 ] = [ 2 5 3 5 ] Solving this with backsubstitution, we find that ( x 1 , x 2 ) = ( − 1 , 3 ) (x_1, x_2) = \boxed{(-1, 3)} ( x 1 , x 2 ) = ( − 1 , 3 ) .
7 Optional: Generalized QR factorizations ¶ In an earlier section , we stated that any real invertible square matrix A A A had a QR decomposition A = Q R A = QR A = QR , where Q Q Q was orthogonal and R R R is upper triangular and invertible.
While this special case (where the R R R matrix is invertible) is incredibly useful for solving systems of linear equations, it turns out that every m × n m\times n m × n matrix A A A has a decomposition of the form A = Q R A = QR A = QR , where Q Q Q is and orthogonal m × m m\times m m × m matrix and R R R is an upper triangular m × n m\times n m × n matrix.
Definition 3 (The QR Factorization)
Any real square matrix A A A may be written in the form
A = Q R \begin{align*}
A = QR
\end{align*} A = QR where Q Q Q is orthogonal and R R R is upper triangular.
Furthermore, if A A A is a real, invertible, square matrix then R R R is invertible.