QR Decomposition Calculator
QR Factorization Calculator
Decompose a matrix into Q (orthogonal) and R (upper triangular) using Gram-Schmidt process. Supports 2x2 and 3x3 matrices.
QR Decomposition Results
Matrix Q (Orthogonal)
Q Properties:
QᵀQ = I (Identity), det(Q) = ±1
Matrix R (Upper Triangular)
R Properties:
Upper triangular, rij=0 for i>j
Verification Results:
||A - QR|| = 0.0000 (Perfect decomposition)
QᵀQ = I: True (Orthogonal matrix verified)
|det(Q)| = 1.0000 (Orthogonal matrix)
QR decomposition factorizes a matrix into an orthogonal matrix Q and an upper triangular matrix R. This is useful for solving linear systems, least squares problems, and eigenvalue computations.
What is QR Decomposition?
QR Decomposition (also called QR Factorization) is a matrix decomposition technique that factors any real square matrix A into the product of an orthogonal matrix Q and an upper triangular matrix R: A = QR.
The matrix Q is orthogonal (QᵀQ = I, where I is the identity matrix), and R is upper triangular (all entries below the main diagonal are zero). This decomposition is unique if A has full column rank and we require R to have positive diagonal entries.
QR Decomposition Methods
Gram-Schmidt Process
Most intuitive method
Step-by-step orthogonalization
Householder Reflections
Better for computers
Uses reflection matrices
Givens Rotations
Element-wise elimination
Useful for sparse matrices
Gram-Schmidt Process Step-by-Step
For Matrix A with columns a₁, a₂, a₃:
- First vector: u₁ = a₁, q₁ = u₁/||u₁||
- Second vector: u₂ = a₂ - (a₂·q₁)q₁, q₂ = u₂/||u₂||
- Third vector: u₃ = a₃ - (a₃·q₁)q₁ - (a₃·q₂)q₂, q₃ = u₃/||u₃||
- Matrix Q: Columns are q₁, q₂, q₃
- Matrix R: R = QᵀA (automatically upper triangular)
- Verification: Check A = QR and QᵀQ = I
Applications of QR Decomposition
Linear Algebra & Numerical Analysis
- Solving linear systems: Ax = b becomes QRx = b → Rx = Qᵀb (easy to solve)
- Least squares problems: Minimize ||Ax - b||² using normal equations
- Eigenvalue algorithms: QR algorithm for computing eigenvalues
- Matrix inversion: Compute A⁻¹ = R⁻¹Qᵀ (triangular inversion is efficient)
Signal Processing & Data Science
- Orthogonal matching pursuit: Sparse signal reconstruction
- Principal Component Analysis: Alternative computation method
- Kalman filtering: Square root filtering implementations
- Image compression: Block-based transformations
Engineering & Physics
- Structural analysis: Stability computations
- Control systems: State-space realizations
- Quantum mechanics: Orthogonal basis transformations
- Computer graphics: Orthonormal coordinate systems
Properties of QR Decomposition
| Property | Description | Mathematical Expression | Importance |
|---|---|---|---|
| Orthogonality of Q | QᵀQ = I (identity matrix) | Columns of Q are orthonormal | Preserves vector lengths and angles |
| Upper Triangular R | rᵢⱼ = 0 for i > j | All entries below diagonal are zero | Easy to solve linear systems |
| Uniqueness | Unique with positive diagonal of R | If A has full column rank | Deterministic computation |
| Numerical Stability | Householder > Modified GS > Classical GS | Error propagation control | Important for large matrices |
Example: QR Decomposition of 2×2 Matrix
Let A = [[3, 1], [4, 2]]
- Column vectors: a₁ = [3, 4]ᵀ, a₂ = [1, 2]ᵀ
- First orthonormal vector: q₁ = a₁/||a₁|| = [3/5, 4/5]ᵀ = [0.6, 0.8]ᵀ
- Project a₂ onto q₁: (a₂·q₁) = (1×0.6 + 2×0.8) = 2.2
- Orthogonal component: u₂ = a₂ - 2.2q₁ = [1, 2]ᵀ - [1.32, 1.76]ᵀ = [-0.32, 0.24]ᵀ
- Second orthonormal vector: q₂ = u₂/||u₂|| = [-0.8, 0.6]ᵀ
- Matrix Q: [[0.6, -0.8], [0.8, 0.6]]
- Matrix R: R = QᵀA = [[5, 2.2], [0, 0.4]]
- Verification: QR = [[3, 1], [4, 2]] = A ✓
Common Examples
Identity Matrix
Orthogonal Matrix
Triangular Matrix
Related Calculators
Frequently Asked Questions (FAQs)
Q: What's the difference between QR and LU decomposition?
A: QR decomposition produces an orthogonal Q and upper triangular R, while LU decomposition produces lower triangular L and upper triangular U. QR works for any matrix (even rectangular), while LU requires square matrices and may need pivoting for stability.
Q: Why is QR decomposition numerically unstable with classical Gram-Schmidt?
A: Classical Gram-Schmidt suffers from loss of orthogonality due to rounding errors. Modified Gram-Schmidt or Householder reflections are preferred for numerical stability, especially for ill-conditioned matrices.
Q: Can QR decomposition handle rectangular matrices?
A: Yes! QR decomposition works for m×n matrices (m ≥ n). Q is m×m orthogonal, and R is m×n upper triangular (or can be reduced to n×n by taking economy-size QR).
Q: How is QR decomposition used in least squares problems?
A: For least squares min ||Ax - b||², we compute QR of A. Then the normal equations become RᵀRx = RᵀQᵀb, which simplifies to Rx = Qᵀb (since RᵀR is easy to invert and QᵀQ = I).
Master matrix factorization with Toolivaa's free QR Decomposition Calculator, and explore more linear algebra tools in our Math Calculators collection.