[SciPy-user] Re: optimize.leastsq and uncertianty in results

R. Padraic Springuel rspringuel at smcvt.edu
Fri Feb 11 13:04:18 CST 2005

Okay, as a test of this possibility I tried the following:

from scipy import *
x = arange(100.)
y = x**2
def residuals(parms,y,x):
    z = parms[0]*x**2 + parms[1]*x + parms[2]
    err = y - z
    return err
fit = optimize.leastsq(residuals,[0,1,2],args=(y,x),full_output=1)
fjac = fit[1].get('fjac')
errors = sqrt(diagonal(matrixmultiply(fjac,transpose(fjac))))
print fit[0]
print errors

Now this should be a simple function to fit, considering there is no 
noise in the "data" and the fit routine itself runs fairly quickly and 
returns reasonable results.  However, the errors are far from 
reasonable.  Am I missing something, or are the results from leastsq 
really that uncertain (despite being a good fit)?


R. Padraic Springuel

More information about the SciPy-user mailing list