[SciPy-User] Simple root solving issues
Gökhan Sever
gokhansever@gmail....
Sun Oct 24 15:43:34 CDT 2010
Hello,
I have a simple test case below:
#!/usr/bin/env python
import numpy as np
from scipy.optimize import leastsq, fsolve
def fitfunc(gsd):
#return dH_dlogDP1 -
(h1.sum()/((2*np.pi)**0.5*np.log(gsd)))*np.exp(-(np.log(Dp1)-np.log(Dp1))**2./(2.*np.log(gsd)**2.))
return dH_dlogDP1 - (h1.sum()/((2*np.pi)**0.5*np.log(gsd)))
dH_dlogDP1 = np.array([ 869.11014589])
Dp1 = np.array([ 0.02994996])
h1 = np.array([ 1906.7283])
res = leastsq(fitfunc, x0=1.5)
res2 = fsolve(fitfunc, x0=1.0)
return terms in fitfunc are equivalent since np.exp(-0) = 1
I hand-solve this equation and find gsd as ~2.4. Both leastsq and
fsolve requires initial estimates to work properly. Now the problem is
they are very sensitive
to the selection of initial parameter. x0=1.5 works (gives ~2.39)
whereas x0=1.0 situation can't estimate a solution.
Is there a way to improve this sensitive init estimate issue with an
alternative approach?
Thanks.
--
Gökhan
More information about the SciPy-User
mailing list