Fitting data with python

Curve fitting
Preparing noisy data:

Using a polynomial fit that is based on generalized linear regression algorithm, solving a linear system. fitpoly is a function and coeff are the coefficients of the optimal polynomial.

Using curve-fit that calls *leastsq* algorithm, taking a step-by-step search for the minimum. The last lines provides the found optimal parameters and their uncertainties. It is worth trying several guesses p0.

Plotting the results:

Using the least-square function directly
The basic syntax is the following: