Simple least squares and curve fitting functions