Least squares curve fitting