Linear least squares#
Linear least squares refers to the problem of minimizing \(\chi^2\) with a model that can be written as a linear combination of basis functions \(f_j(x)\) as
where \(a_j\) are the model parameters. For example if we wanted to fit a polynomial we would choose \(f_j(x) = x^{j-1}\) and minimize \(\chi^2\) to find the polynomial coefficients \(\{a_j\}\).
We’ll follow the analysis of Numerical Recipes with some small changes in notation. Write out \(\chi^2\) and minimize it:
At this point it is useful to define the design matrix
and also the vector \(\vec{d}\) which is the data weighted by the errors at each point:
Then we have
So in matrix form, we have
These are known as the normal equations for the linear least squares problem.
We’ve assumed here that the noise is uncorrelated between measurements (the noise on one measurement does not depend on the noise on a previous measurement). The normal equations can be generalized to include correlated noise, but we’ll leave this for later and for now focus on how we can solve these equations.
Exercise:
Show that \(\chi^2\) can be written in our matrix notation as