Least Squares Solver using QR Decomposition

Find the best approximate solution to \(A\mathbf{x} \approx \mathbf{b}\) using QR Decomposition1.
Minimizes the Euclidean norm \(\|A\mathbf{x} - \mathbf{b}\|_2\) via Householder reflections2.

When the system \(A\mathbf{x} = \mathbf{b}\) is overdetermined (more equations than unknowns), we find the solution that minimizes the residual:

\[\min_{\mathbf{x}} \|A\mathbf{x} - \mathbf{b}\|_2\]

QR Method:

  • Factor \(A = QR\) where \(Q\) is orthogonal and \(R\) is upper triangular3
  • Compute \(c = Q^T\mathbf{b}\), then solve \(R\mathbf{x} = c\)
  • More numerically stable than the normal equations4

Advantages:

  • Handles rank-deficient matrices gracefully
  • Provides minimum-norm solution for underdetermined systems
  • Uses Householder reflections for robust computation

Display modes: Surd (default) — shows entries of \(Q\), \(R\), and \(c=Q^T\mathbf{b}\) as exact radicals like \(\tfrac{1}{\sqrt{2}}\) when possible, falling back to fractions or decimals otherwise. Decimal and Fraction modes are also available.

Set matrix dimensions

Enter dimensions and click Generate Matrix to create the input grid and b vector.

Display values as:
Compute
Solves the least-squares problem via QR decomposition and back substitution.
Resets all dimensions, matrix entries, and results.