The astronomers and surveyors of the eighteenth century had a problem in common. To determine a few quantities, such as the elements of a comet’s orbit or the flattening of the Earth, they made many observations, more than the number of unknowns. Each observation gave an equation, but the equations, because of small measurement errors, did not agree with one another: no values of the unknowns satisfied all of them at once. Which values should one choose?

There were recipes. Tobias Mayer grouped the equations and added up each group; Boscovich and Laplace minimised the sum of the errors in absolute value, or the largest error. None was both simple and general.

The appendix of 1805

In 1805 Legendre published a small book, New methods for the determination of the orbits of comets, and added at the end a nine-page appendix: On the method of least squares. The first page already says it all.

First page of the appendix "On the method of least squares", in the *New methods for the determination of the orbits of comets* (1805). The error equations appear in the form E = a + bx + cy + fz + &c.
First page of the appendix “On the method of least squares”, in the New methods for the determination of the orbits of comets (1805). The error equations appear in the form E = a + bx + cy + fz + &c.Asiatic Society of Mumbai, via Internet Archive · Wikimedia Commons · public domain

Legendre writes each observation equation in the form $E = a + bx + cy + fz + \cdots$, where $a, b, c, f$ are known numbers, $x, y, z$ are the unknowns and $E$ is the error, which one wants to be small. Since one cannot make all the errors vanish, he proposes to make the sum

$$E_1^2 + E_2^2 + \cdots + E_m^2$$

a minimum.

By this means there is established among the errors a kind of equilibrium which, preventing the extremes from prevailing, is very well suited to revealing the state of the system that is nearest to the truth.

— Legendre, Nouvelles méthodes (1805), appendix

The normal equations

The great advantage of squares is that the minimum is found by solving linear equations. Differentiating the sum with respect to $x$ and setting it to zero,

$$\frac{\partial}{\partial x}\sum E_i^2 = 2\sum E_i\,b_i = 0,$$

and likewise for each unknown. One obtains a system with as many equations as unknowns, which we now call the normal equations. Legendre gives the recipe in words: multiply each equation by its coefficient of $x$ and add them all up; do the same with $y$, with $z$, and solve.

Let us look at the simplest case, that of a line $y = a + bx$ fitted to the points $(0, 1)$, $(1, 3)$, $(2, 4)$ and $(3, 4)$. The errors are $E_i = a + bx_i - y_i$, and the normal equations become

$$\begin{aligned} n\,a + \left(\textstyle\sum x_i\right) b &= \textstyle\sum y_i, \\ \left(\textstyle\sum x_i\right) a + \left(\textstyle\sum x_i^2\right) b &= \textstyle\sum x_i y_i. \end{aligned}$$

With $n = 4$, $\sum x_i = 6$, $\sum x_i^2 = 14$, $\sum y_i = 12$ and $\sum x_i y_i = 0 + 3 + 8 + 12 = 23$:

$$4a + 6b = 12, \qquad 6a + 14b = 23.$$

By Cramer’s rule, with determinant $4 \cdot 14 - 6 \cdot 6 = 20$,

$$a = \frac{12 \cdot 14 - 6 \cdot 23}{20} = \frac{30}{20} = 1.5, \qquad b = \frac{4 \cdot 23 - 6 \cdot 12}{20} = \frac{20}{20} = 1.$$

The line is $y = 1.5 + x$. The errors are $0.5$, $-0.5$, $-0.5$ and $0.5$, and the sum of their squares is $1$. No other line does better. In the figure, try it: drag the points and look, with the controls, for a better line than Legendre’s.

Legendre also remarks in the appendix that when there is only one unknown and all the observations measure it directly, the method gives the arithmetic mean of the observations. The rule everyone used out of common sense became a special case of a general principle.

The quarrel with Gauss

In 1809 Gauss published the Theory of the motion of the heavenly bodies, in which he used the same method and called it “our principle, which we have made use of since 1795”. Gauss said it was with it that, in 1801, he had computed the orbit of the dwarf planet Ceres, which astronomers had lost sight of. Legendre was furious. He wrote to Gauss pointing out that priority for a discovery is established by publication, and came back to the matter, bitterly, in a supplement of 1820.

Historians today agree that Gauss probably was using the method before 1805, and that Legendre was the first to publish it and explain it clearly. Gauss added something Legendre did not have: a justification. Assuming that the errors follow the bell-shaped curve that now bears his name, he showed that least squares gives the most probable values of the unknowns. Soon afterwards Laplace showed, with the central limit theorem, that this curve appears naturally when an error is the sum of many small errors. Within a few years, Legendre’s method was in every observatory in Europe.

Exercise: the mean is the best value

Show that the number $a$ that makes the sum $(x_1 - a)^2 + \cdots + (x_n - a)^2$ a minimum is the mean $\bar x = \frac{x_1 + \cdots + x_n}{n}$.

Differentiating with respect to $a$: $-2\left[(x_1 - a) + \cdots + (x_n - a)\right] = 0$, that is, $x_1 + \cdots + x_n = n a$, and $a = \bar x$. Since the second derivative is $2n > 0$, it is indeed a minimum. This is the one-unknown case that Legendre pointed out.

Exercise: the line through three points

Fit a line $y = a + bx$ to the points $(1, 2)$, $(2, 3)$ and $(3, 5)$ by Legendre’s method.

We have $n = 3$, $\sum x_i = 6$, $\sum x_i^2 = 14$, $\sum y_i = 10$ and $\sum x_i y_i = 2 + 6 + 15 = 23$. The normal equations are $3a + 6b = 10$ and $6a + 14b = 23$, with determinant $42 - 36 = 6$:

$$a = \frac{10 \cdot 14 - 6 \cdot 23}{6} = \frac{1}{3}, \qquad b = \frac{3 \cdot 23 - 6 \cdot 10}{6} = \frac{3}{2}.$$

The line is $y = \frac{1}{3} + \frac{3}{2}x$. The errors $E_i = a + bx_i - y_i$ at the three points are $-\frac{1}{6}$, $\frac{1}{3}$ and $-\frac{1}{6}$, which add up to zero, as always happens when the equation has a constant term.

Sources: Adrien-Marie Legendre, Nouvelles méthodes pour la détermination des orbites des comètes (1805), appendix · Carl Friedrich Gauss, Theoria motus corporum coelestium (1809) · Stephen M. Stigler, The History of Statistics (1986), ch. 1, and “Gauss and the invention of least squares”, Annals of Statistics 9 (1981).


All topics on Adrien-Marie Legendre · ← How many primes are there up to x · Forty years of elliptic integrals →

Image credits.