Using least squares to fit a curve to data