stepik: https://stepik.org/a/248961
🚀 Professional implementation of QR Factorization with mathematical derivation and Python solver.
This repository contains a complete course-style implementation of QR Factorization including:
- Mathematical derivation
- Geometric interpretation
- Gram–Schmidt algorithm
- Modified Gram–Schmidt
- Householder reflections
- Numerical stability analysis
- Python implementation from scratch
qr factorization
qr decomposition
qr solver python
qr factorization from scratch
numerical linear algebra
matrix decomposition
householder transformation
gram schmidt orthogonalization
least squares qr
linear algebra course
QR Factorization decomposes a matrix:
into:
Where:
-
$$Q \in \mathbb{R}^{m \times m}$$ — orthogonal matrix
Q^T Q = I -
$$R \in \mathbb{R}^{m \times n}$$ — upper triangular matrix
QR Factorization represents:
- Rotation / reflection of vectors
- Orthogonal basis construction
- Projection onto orthonormal space
Householder transformation:
Used for stable QR computation.
QR Factorization is used in:
- Solving linear systems
- Least squares problems
- Eigenvalue algorithms (QR algorithm)
- Machine learning optimization
- Numerical stability improvement
qr-factorization-solver/
│
├── README.md
├── LICENSE
├── requirements.txt
│
├── src/
│ ├── qr_gram_schmidt.py
│ ├── qr_modified.py
│ ├── qr_householder.py
│
├── examples/
│ └── demo.py
│
├── docs/
│ ├── theory.md
│ ├── stability.md
│
├── images/
│ └── qr_geometry.png
│
└── index.html
import numpy as np
def qr_gram_schmidt(A):
A = A.astype(float)
m, n = A.shape
Q = np.zeros((m, n))
R = np.zeros((n, n))
for k in range(n):
v = A[:, k]
for j in range(k):
R[j, k] = np.dot(Q[:, j], A[:, k])
v = v - R[j, k] * Q[:, j]
R[k, k] = np.linalg.norm(v)
Q[:, k] = v / R[k, k]
return Q, Rpip install -r requirements.txtRun example:
python examples/demo.py