Find a zero using the Newton-Raphson or secant method.
Find a zero of the function func given a nearby starting point x0. The Newton-Raphson method is used if the derivative fprime of func is provided, otherwise the secant method is used. If the second order derivate fprime2 of func is provided, parabolic Halley’s method is used.
Parameters : | func : function
x0 : float
fprime : function, optional
args : tuple, optional
tol : float, optional
maxiter : int, optional
fprime2 : function, optional
|
---|---|
Returns : | zero : float
|
Notes
The convergence rate of the Newton-Raphson method is quadratic, the Halley method is cubic, and the secant method is sub-quadratic. This means that if the function is well behaved the actual error in the estimated zero is approximately the square (cube for Halley) of the requested tolerance up to roundoff error. However, the stopping criterion used here is the step size and there is no guarantee that a zero has been found. Consequently the result should be verified. Safer algorithms are brentq, brenth, ridder, and bisect, but they all require that the root first be bracketed in an interval where the function changes sign. The brentq algorithm is recommended for general use in one dimensional problems when such an interval has been found.