[SciPy-user] scipy.optimize.leastsq failure

fdu.xiaojf@gmai... fdu.xiaojf@gmai...
Mon Aug 27 03:57:18 CDT 2007


Hi,

I get an ier flag of 2 when running the following code:

----------------------------------------------------------
from scipy.optimize import leastsq
from numpy import array

x = array([1.2, 3.4, 5.6, 7.8])
y = (x-1.234)**2+3.456

def obj_f(pp, xx, yy):
     return pp[0] * (xx-pp[1])**2 + pp[2] - yy

b = leastsq(obj_f, (1., 1., 2.), args=(x,y), full_output=2)
print b
print obj_f(b[0], x, y)
----------------------------------------------------------

The output is:
----------------------------------------------------------
(array([ 1.   ,  1.234,  3.456]), array([[ 0.01067209,  0.03485503,  0.04927042],
        [ 0.03485503,  0.12416711,  0.22839652],
        [ 0.04927042,  0.22839652,  0.91824454]]), {'qtf': array([ 
-5.72325346e-10,  -3.96833152e-10,  -2.98440470e-11]), 'nfev': 13, 'fjac': 
array([[-47.37134237,   0.09903785,   0.40239425,   0.9100936 ],
        [ 15.89408601,   3.85306656,   0.61349297,  -0.32983294],
        [ -1.41155008,  -0.95837977,   1.04356817,   0.82836952]]), 'fvec': 
array([ -8.88178420e-16,   0.00000000e+00,   0.00000000e+00,
         -7.10542736e-15]), 'ipvt': array([1, 2, 3])}, 'The relative error 
between two consecutive iterates is at most 0.000000', 2)
[ -8.88178420e-16   0.00000000e+00   0.00000000e+00  -7.10542736e-15]
----------------------------------------------------------

Tt seems that the result is rather accurate, but while I get an ier flag of 2?
I don't quite understand the error message.

Regards,


More information about the SciPy-user mailing list