Skip to main content
Numerical analysis
Lesson 43 of 75
Standard practice

Numerical least squares

Objective. Use QR methods for stable fitting.

  1. 1. Learn
  2. 2. Worked example
  3. 3. Practice
  4. 4. Feedback
  5. 5. Continue

Learn: the key idea

Numerical least squares finds the vector x minimising ‖Ax − b‖² for an overdetermined system, using a QR factorisation of A for numerical stability rather than forming the ill-conditioned normal equations AᵀAx = Aᵀb directly. Writing A = QR with Q orthogonal and R upper triangular, the problem reduces to solving Rx = Qᵀb by back substitution, since ‖Ax − b‖ = ‖Rx − Qᵀb‖. For example, fitting a line to points (0,1), (1,2), (2,2) sets up a 3×2 matrix A whose QR factorisation yields a stable triangular system for the slope and intercept. QR avoids squaring the condition number that normal equations introduce.

Worked example

Using least squares, fit y = c (a constant) to the data points (1,2), (2,4), (3,3), finding the value of c that minimises the sum of squared residuals.

Diagram of a square
  1. 1Model: A is a column of ones, so the normal equation becomes 3c = Σyᵢ.
  2. 2Sum the y-values: 2 + 4 + 3 = 9.
  3. 3Solve 3c = 9 to give c = 3.
  4. 4Check: residuals are −1, 1, 0, summing to zero as required for a least-squares constant fit.

Answer: c = 3

Concept mastery

Based on your past attempts at this lesson — the question types to practise again come first.

Complete a practice set to see your concept breakdown here.

Practice

Practice happens on its own screen, one question at a time. Answers stay hidden until you submit yours, and you can stop and pick up at the same question later.

Start practising

Common mistake. Students solve AᵀAx = Aᵀb directly for a fit and get inaccurate coefficients when A is ill-conditioned, because squaring A in AᵀA doubles the condition number; using QR decomposition avoids this amplification of rounding error.

Your progress

Tick each step as you finish it. Your exact reading position is saved automatically, so Continue drops you back on the same line.

0 of 5 steps complete

Your place saves automatically as you read.

My dashboard