[SciPy-User] Simple root solving issues
Charles R Harris
Sun Oct 24 16:14:06 CDT 2010
On Sun, Oct 24, 2010 at 2:43 PM, Gökhan Sever <email@example.com> wrote:
> 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 -
> 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?
Looks pretty much like a hyperbola here, it's the division by the log term.
Are you sure this is the right example?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User