[SciPy-Dev] Comments on optimize.newton function

Gökhan Sever gokhansever at gmail.com
Sat May 21 18:24:12 EDT 2011


Hello,

Could we add "tolf" argument into the newton function signature?

I am guessing this should match the tolf argument in IDL newton (
http://star.pst.qub.ac.uk/idl/NEWTON.html)

TOLF: Set the convergence criterion on the function values. The default
value is 1.0 x 10-4.


def newton(func, x0, fprime=None, args=(), tol=1.48e-8, maxiter=50, tolf=
1.e-4)

In second method part of the newton function (from
https://github.com/scipy/scipy/blob/master/scipy/optimize/zeros.py)

        # Secant method
        p0 = x0
        if x0 >= 0:
            p1 = x0*(1 + 1e-4) + 1e-4
        else:
            p1 = x0*(1 + 1e-4) - 1e-4

without increasing the tolf or (1e-4) in these statements I can't get
a proper root solution for my function.



The reason that I am experiencing with newton is because fsolve seems
slower comparing to the newton for scalar root finding for a given
function.

Consider this example run Sage v4.6.1 notebook:


%cython
cpdef double myfunc(double x):
    return x**3 + 2*x - 1


timeit('scipy.optimize.newton(myfunc,1)')

625 loops, best of 3: 22.1 µs per loop


timeit('scipy.optimize.fsolve(myfunc,1)')

625 loops, best of 3: 86.5 µs per loop


I am also experimenting to Cythonize the Newton secant method, which the
Cython written version shows significant speed-ups comparing to the Python
version. Without going any further, I would like to know if there is any
Cythonized code around for newton or any other approach to make fsolve
faster?

Thanks.


-- 
Gökhan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20110521/60b2279c/attachment.html>


More information about the SciPy-Dev mailing list