For AI agents: use /llms.txt for the Nakafa content index.
We want to transform a matrix into upper triangular form, but not through elementary row operations, rather through orthogonal transformations that have better conditioning. Imagine rotating and reflecting geometric space to simplify the matrix, without changing its fundamental properties.
Let A∈Rm×n be a rectangular matrix with m≥n and . Then there exists an orthogonal matrix with and an upper triangular matrix with diagonal elements for , such that:
RankA=n Q∈Rm×m R∈Rm×n i=1,…,n This representation is called the QR decomposition of A.
The columns aj for j=1,…,n of matrix A can be orthonormalized using the Gram-Schmidt process:
We obtain orthonormal vectors qj for j=1,…,n as columns of the orthogonal matrix Q1∈Rm×n. Conversely:
Thus A=Q1R1 with upper triangular matrix R1∈Rn×n whose diagonal elements are rii=∥q~i∥2>0.
If Q1 is completed with m−n additional columns to become orthogonal matrix Q=(Q1Q2)∈Rm×m and R1 becomes R=(R10)∈Rm×n, then A=Q1R1=QR.
When we have a matrix A∈Rm×n with m≥n,
there are two ways to represent the QR decomposition. The difference lies in the size of the matrices used.
Full QR decomposition uses full-sized matrices:
with Q∈Rm×m being a full-sized orthogonal matrix and
R∈Rm×n being an upper triangular matrix.
Since the lower part of matrix R only contains zeros, we can save storage and computation.
Economical QR decomposition only uses the parts that are actually needed:
Here Q1∈Rm×n only takes the first through n-th columns
from Q, and R1∈Rn×n is a square upper triangular matrix.
Why is it called economical? Because we save storage space and computational time.
Instead of storing matrix Q of size m×m which can be very large,
we only need Q1 of size m×n.
The columns of matrix Q2∈Rm×(m−n) that we don't use form
an orthonormal basis of KernelAT:
The economical QR decomposition A=Q1⋅R1 with condition rii>0
for all i=1,…,n is unique for matrix A
that has full rank.
Although the Gram-Schmidt process provides an elegant theoretical way to obtain QR decomposition,
this method is not suitable for practical computation. The main problem is numerical instability due to cancellation,
orthogonality of columns is quickly lost during computation.
To overcome this problem, we need a method that is more numerically stable.
One of the most successful approaches is the Householder procedure,
which uses orthogonal reflection transformations. Another alternative is the Givens procedure with rotation transformations.
For a vector v∈Rm with ∥v∥2=1,
we can define the Householder transformation matrix:
Note that vvT is a dyadic product, which is the multiplication of column vector
v∈Rm×1 with row vector vT∈R1×m.
The result of this multiplication is an m×m matrix with rank 1 for v=0.
Don't confuse this with scalar multiplication vTv∈R.
Let S=I−2vvT∈Rm×m be a Householder transformation matrix
for vector v∈Rm with ∥v∥2=1. Then it holds:
-
S is symmetric: ST=S
-
S is an orthogonal matrix: STS=I
-
Multiplication S⋅x of S from the left with vector x∈Rn
causes reflection of x in the subspace ,
that is, in the hyperplane with normal vector
-
cond2(S)=1
Given matrix A∈Rm×n with m≥n
and RankA=n. For QR decomposition computation,
matrix A is transformed column by column through Householder reflections
into upper triangular form.
Start with A1=A and reflect the first column of A1
with respect to a vector using reflection plane with:
Householder transformation matrix S1=Im−2v1v1T∈Rm×m. We obtain:
with r11=±∥a~1∥2 and A~2∈Rm−1×n−1.
Continue with reflection of the first column of the submatrix with reflection plane:
With transformation matrix:
with r22=±∥a~2∥2 and A~3∈Rm−2×n−2, and so on until:
Finally we obtain the upper triangular matrix:
Thus we obtain the factorization:
with Q being an orthogonal matrix.
Implementation of the Householder procedure:
For i=1,…,n:
The numerical complexity for computing QR decomposition of matrix A∈Rm×n
with Householder procedure is essentially:
-
Due to orthogonal transformation, it holds that cond2(R)=cond2(A)
-
The diagonal elements of R are the numbers ±∥a~i∥2
from the i-th step. Choosing the transformation so that all are positive gives the QR decomposition.
If ∥a~i∥2=0, A does not have full rank
and the algorithm stops.
For numerical reasons choose the sign so that cancellation is avoided:
-
Instead of constructing Q, in compact storage one can also store
only the information needed for the transformation:
-
If you only want to compute economical QR decomposition, remove the corresponding columns of Q and rows of R.
Span(v)⊥ in the free space of A below the diagonal and diagonal elements in an additional vector.