Maths WorkshopMaths problems with full solutions
Exercise 116Calculus › Single-variable calculus › Differentiation › Optimisation and curve sketchingL1Added 4 Nov 2026

Least squares for a line through the origin

#least squares#regression#statistics#quadratic

Statement

We have the data points (1,2)(1,2), (2,3)(2,3), (3,7)(3,7) and want a line y=axy=ax through the origin fitting them best in the least squares sense, i.e. minimising S(a)=∑i(yi−axi)2S(a)=\sum_i(y_i-ax_i)^2.

  1. Find aa.
  2. Find the general formula for nn points.
Hint

SS is a quadratic polynomial in aa.

Show solutionHide solution

Solution

1. S(a)=(2−a)2+(3−2a)2+(7−3a)2=14a2−58a+62S(a)=(2-a)^2+(3-2a)^2+(7-3a)^2=14a^2-58a+62. Then S′(a)=28a−58=0S'(a)=28a-58=0 gives
a=2914≈2.07.a=\frac{29}{14}\approx2.07.
The minimal value is S=62−29214=2714≈1.93S=62-\dfrac{29^2}{14}=\dfrac{27}{14}\approx1.93.

2. For nn points, S(a)=a2∑xi2−2a∑xiyi+∑yi2S(a)=a^2\sum x_i^2-2a\sum x_iy_i+\sum y_i^2 and
S′(a)=0  ⟺  a=∑xiyi∑xi2S'(a)=0\iff a=\frac{\sum x_iy_i}{\sum x_i^2}
(provided not all xix_i are 00). For the data above, ∑xiyi=29\sum x_iy_i=29 and ∑xi2=14\sum x_i^2=14.

Remark. Convexity (S′′=2∑xi2>0S''=2\sum x_i^2>0) guarantees that the critical point is the global minimum. With a free intercept (y=ax+by=ax+b) one has two parameters and gets the usual regression line, but the idea is the same.