Solution (source code)

= Solution

Compute the two sides of the <normal equations for linear least squares> and divide by $n$:
$$
\begin{pmatrix}1&\overline x\\\overline x&\overline{x^2}\end{pmatrix}
\begin{pmatrix}\alpha\\\beta\end{pmatrix}
=\begin{pmatrix}\overline y\\\overline{xy}\end{pmatrix}.
$$
The first equation gives $\alpha=\overline y-\beta\overline x$. Substitute this into the second and solve:
$$
\boxed{\beta=\frac{\overline{xy}-\overline x\,\overline y}{\overline{x^2}-\overline x^{\,2}},\qquad
\alpha=\frac{\overline{x^2}\,\overline y-\overline x\,\overline{xy}}{\overline{x^2}-\overline x^{\,2}}.}
$$
These <simple linear regression> coefficients are unique provided the observed distances are not all equal, since
$$
\overline{x^2}-\overline x^{\,2}=\frac1n\sum_{i=1}^n(x_i-\overline x)^2>0.
$$
The condition $n\ge2$ alone does not guarantee this. If all $x_i=x_0$, the <design matrix> has <matrix rank> one and the valid alternative is the family
$$
\boxed{\alpha+x_0\beta=\overline y,\qquad\beta\text{ arbitrary}.}
$$
In this <rank-deficient ordinary least squares> case, the fitted predictions are uniquely $\overline y$ but the two parameters cannot be separately determined.