qr factorisation calculator

Interactive QR Factorisation Calculator

Enter a real matrix A, then compute A = QR using modified Gram-Schmidt. This tool returns a thin Q (m×n) and an upper-triangular R (n×n).

What is QR factorisation?

QR factorisation writes a matrix A as a product A = QR, where Q has orthonormal columns and R is upper triangular. If your matrix has dimensions m×n with m ≥ n, the “thin” QR gives Q as m×n and R as n×n.

Intuitively, QR takes your original column vectors and turns them into a clean orthonormal basis (Q), then stores the scaling and mixing information in R. This is one of the most useful matrix decompositions in numerical linear algebra.

Why this decomposition matters

  • Least squares: Solve overdetermined systems (more equations than unknowns) without forming unstable normal equations.
  • Numerical stability: Orthogonal operations are generally more stable than direct elimination in many contexts.
  • Eigenvalue methods: The QR algorithm is foundational in computing eigenvalues.
  • Data science and ML: Useful in regression workflows, orthogonal projections, and dimensional analysis.

How this calculator computes QR

This page uses modified Gram-Schmidt. For each column of A:

  1. Subtract projections onto previously computed orthonormal vectors.
  2. Normalize the remaining vector to create a new column of Q.
  3. Store projection coefficients and norms inside R.

If a pivot norm becomes too small, the matrix columns are linearly dependent (or very close), and a full-rank thin QR is not possible with this routine.

How to use the calculator

1) Pick matrix size

Set rows and columns, then click Build Matrix. For thin QR in this implementation, use m ≥ n.

2) Enter values

Fill each cell with a real number. Decimals and negative values are supported.

3) Compute

Click Compute QR to produce Q, R, and a reconstructed matrix QR. The tool also reports:

  • Reconstruction error: max |A - QR|
  • Orthogonality error: max |QTQ - I|

Smaller errors indicate better numerical quality.

Interpretation tips

Q matrix

Columns of Q are orthonormal directions spanning the same column space as A. In geometry terms, they are clean unit axes fitted to your original columns.

R matrix

R captures how each original column can be formed from those orthonormal directions. Because R is upper triangular, dependencies are accumulated in a structured way from left to right.

Common applications

  • Linear regression and least squares fitting
  • Signal processing projection problems
  • Scientific computing with tall matrices
  • Preconditioning and orthogonalization in iterative methods

Limitations and practical notes

This calculator is designed for learning and small matrices (up to 8×8 input controls by default). For production workloads, use optimized libraries (Householder QR, blocked algorithms, LAPACK-backed tools) for improved robustness and speed on large problems.

🔗 Related Calculators