[SciPy-User] Vectorized newton function

Gökhan Sever gokhansever@gmail....
Wed Apr 14 19:15:40 CDT 2010


Thanks Anne for suggesting "fsolve" and rest of the useful information.
Below is how my function is read:

def myfunc(myarray):
       term1 = compute1_array1
       term2 = compute3_array2
       term3 = compute3_array3
       return term1+term2+term3

result_arr = fsolve(myfunc, myarray)

IDL handles univariate and multivariate cases using one fun newton function.
I get almost equivalent results using fsolve to IDL's newton.

On Wed, Apr 14, 2010 at 6:23 PM, Anne Archibald
<peridot.faceted@gmail.com>wrote:

> On 14 April 2010 18:37, Gökhan Sever <gokhansever@gmail.com> wrote:
> > Hello,
> >
> > How can I make scipy.optimize.newton function accepting a numpy.array as
> its
> > x0 parameter?
>
> The short answer is, you can't. Just use a loop.
>
> The basic problem is that this function is a univariate optimizer, so
> that it adjusts the scalar x0 as needed to (try to) find a zero of
> func. If func is a multivariate function, you need a multivariate root
> finder like fsolve. If what you want is instead to run one-dimensional
> root-finding with many different starting points, well, I'll first
> point out that the dependence of the result of newton on the starting
> point is complicated (in fact fractal) and nasty, so you're going to
> get weird hard-to-predict results unless you carefully start each x0
> near a zero. If at all possible I recommend using something like
> brentq/brenth that takes a "bracket" instead of a single point. That
> said, if you're looking for lots of roots, there's not really any way
> around looping in python to call newton many times, but this isn't
> your efficiency problem anyway: the python function you provide as
> "func" will be called many times for each call of newton, and that's
> where the python overhead will matter. If your goal is just to avoid
> writing a for loop, you can consider using vectorize() to create the
> python loop for you.
>
> You could argue that newton should allow "parallel" root-finding by
> passing an array of xs into func and the derivative and getting an
> array back, but since newton is an adaptive method, this would be very
> messy code.
>
> Anne
>
> > File:
> /usr/lib/python2.6/site-packages/scipy/optimize/minpack.py
> > Definition:       newton(func, x0, fprime=None, args=(), tol=1.48e-08,
> > maxiter=50)
> >
> > x0 : float
> >         An initial estimate of the zero that should be somewhere near the
> >         actual zero.
> >
> > (Without using a for-loop)
> >
> > Thanks.
> >
> > --
> > Gökhan
> >
> > _______________________________________________
> > SciPy-User mailing list
> > SciPy-User@scipy.org
> > http://mail.scipy.org/mailman/listinfo/scipy-user
> >
> >
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



-- 
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20100414/af89e704/attachment.html 


More information about the SciPy-User mailing list