I want to fit the Lorentzian peak to the dataset x and y, the data is fine. Other programs like OriginLab are perfect, but I wanted to automate the fitting with python, so I have the code below, which is based on http://mesa.ac.nz/?page_id=1800
The problem is that scipy.optimize.leastsq returns, as best fit, the same initial guess parameters that I passed in that I did practically nothing. Here is the code.
p are the initial guesses, and best_parameters are the least-squares returned best-fit parameters, but they are always the same.
this is what full_output = 1 is returned (long numeric arrays have been shortened, but still represent)
[0.055, 855.50732, 1327.0] (array([ 5.50000000e-02, 8.55507324e+02, 1.32700000e+03]), None, {'qtf':array([ 62.05192947, 69.98033905, 57.90628052]), 'nfev': 4, 'fjac': array([[-0., 0., 0., 0., 0., 0., 0.,], [ 0., -0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 0., -0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]), 'fvec': array([ 62.05192947, 69.98033905, 53.41218567, 45.49879837, 49.58242035, 36.66483688, 34.74443436, 50.82238007, 34.89669037]), 'ipvt': array([1, 2, 3])}, 'The cosine of the angle between func(x) and any column of the\n Jacobian is at most 0.000000 in absolute value', 4)
Can anyone understand what is wrong?