[SciPy-User] Simple root solving issues
Charles R Harris
charlesr.harris@gmail....
Sun Oct 24 16:14:06 CDT 2010
On Sun, Oct 24, 2010 at 2:43 PM, Gökhan Sever <gokhansever@gmail.com> wrote:
> 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?
>
>
Looks pretty much like a hyperbola here, it's the division by the log term.
Are you sure this is the right example?
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20101024/3909565a/attachment.html
More information about the SciPy-User
mailing list