Understanding QR Factorization: A Step‑by‑Step Gram‑Schmidt Example for a 3×3 Matrix
This article defines QR factorization, walks through a complete Gram‑Schmidt orthogonalisation of a 3×3 matrix to obtain Q and R, and highlights key uses such as solving linear equations, least‑squares fitting, and eigenvalue algorithms.
Prof. Dr. Vidya Prasad Shukla2 views
Photo by Thomas T on Unsplash
What Is QR Factorization?
QR factorization (or QR decomposition) expresses a real or complex matrix A as the product of an orthogonal (or unitary) matrix Q and an upper‑triangular matrix R:
A=QR
where Q⊤Q=I (or Q∗Q=I) and R has zeros below its main diagonal. The decomposition is fundamental in numerical linear algebra because it separates the geometric information (the orthogonal basis) from the scaling and shear information (the triangular factor).
Why Use QR Factorization?
QR factorization is employed in many computational tasks:
Solving linear systems Ax=b efficiently by solving QRx=b.
Computing least‑squares solutions for over‑determined systems.
Providing a stable basis for eigenvalue algorithms such as the QR algorithm.
Facilitating rank‑revealing decompositions and condition‑number estimates.
Gram‑Schmidt Orthogonalisation – The Core Idea
The classical Gram‑Schmidt process takes a set of linearly independent column vectors of A and orthogonalises them step by step, producing the columns of Q. The coefficients used during orthogonalisation form the entries of R.
Given columns a1,a2,…,an of A, the process computes:
u1=a1,q1=∥u1∥u1
For k≥2:
uk=ak−j=1∑k−1(qj⊤ak)qj,
qk=∥uk∥uk.
The inner products (qj⊤ak) become the entries rjk, while rkk=∥uk∥.
Step‑by‑Step Example: A 3×3 Matrix
Consider the matrix
A=110101011.
We will apply Gram‑Schmidt to its columns a1,a2,a3.
The orthogonal matrix Q consists of the three q vectors as columns:
Q=2121061−6162−333333.
The upper‑triangular matrix R collects the coefficients rij:
R=20021230216132.
One can verify that QR reproduces the original A (up to rounding errors) and that Q⊤Q=I.
Photo by S.Hossein Hassanpour on Unsplash
Mid‑Article Illustration
The picture above shows a study group analysing a QR decomposition on a whiteboard, highlighting the collaborative nature of learning higher mathematics.
Practical Uses of QR Factorization
Solving Ax=b: Compute y=Q⊤b and then solve the triangular system Rx=y by back‑substitution.
Least‑Squares Problems: For an over‑determined system Ax≈b, QR yields the minimiser x=R−1Q⊤b without forming A⊤A.
Eigenvalue Computations: The QR algorithm repeatedly factors Ak=QkRk and sets Ak+1=RkQk, converging to a Schur form.
Numerical Stability: Orthogonal transformations preserve vector norms, making QR preferable to Gaussian elimination in many contexts.
Conclusion
QR factorization, built on the Gram‑Schmidt orthogonalisation, provides a clear geometric decomposition of any full‑rank matrix into an orthogonal basis and an upper‑triangular scaling matrix. The step‑by‑step 3×3 example demonstrates how each column of Q is obtained and how R records the projection coefficients. Mastery of QR opens the door to efficient linear‑system solvers, robust least‑squares fitting, and powerful eigenvalue algorithms—tools that are indispensable in scientific computing, data analysis, and engineering design.
Frequently asked questions
What is the main difference between QR factorization and LU decomposition?▾
QR factorization uses an orthogonal matrix Q and an upper‑triangular matrix R, preserving vector norms and offering numerical stability, while LU decomposition splits a matrix into lower‑ and upper‑triangular matrices (L and U) without orthogonal components.
The article introduces singular value decomposition (SVD) as a factorization of any matrix into orthogonal (or unitary) components and shows how replacing non‑zero singular values with their reciprocals produces the Moore‑Penrose pseudoinverse. A concrete 2×2 example illustrates the calculations, and several real‑world uses—such as low‑rank approximation, solving ill‑conditioned systems, latent semantic analysis, and robot kinematics—are discussed.
Can QR factorization be applied to non‑square matrices?▾
Yes. For an m×n matrix with m≥n, QR yields an m×n orthogonal matrix Q (with Q⊤Q=In) and an n×n upper‑triangular R. When m<n, a reduced QR (or thin QR) is used.
Why is the Gram‑Schmidt process considered numerically unstable?▾
In finite‑precision arithmetic, rounding errors can cause the computed qi vectors to lose orthogonality. Modified Gram‑Schmidt or Householder reflections are preferred for higher stability.
How does QR factorization help in solving least‑squares problems?▾
By writing A=QR, the least‑squares solution to min∥Ax−b∥ becomes x=R−1Q⊤b, avoiding the formation of A⊤A which can amplify conditioning issues.
Is QR factorization unique?▾
If all diagonal entries of R are taken to be positive, the QR decomposition of a full‑rank matrix is unique. Changing signs of columns of Q and corresponding rows of R yields alternative valid factorizations.
This article introduces singular value decomposition (SVD) for any real matrix, shows how the same factors yield the Moore‑Penrose pseudoinverse, works through a rank‑deficient 2×2 example, and outlines common applications such as least‑squares solving, low‑rank approximation, and PCA.