Iterative Methods — cxroots 1.1.0 documentation

# Iterative Methods

`cxroots.IterativeMethods.` `iterateToRoot`(x0, f, df=None, steptol=1e-12, roottol=1e-12, maxIter=20, attemptBest=False, verbose=False, callback=None)

  Starting with initial point x0 iterate to a root of f. This function is called during the rootfinding process to refine any roots found. If df is given then the Newton-Raphson method, `newton()`, will be used, otherwise Muller’s method, `muller()`, will be used instead.

  Parameters: | x0 (complex) – An initial point for the iteration. f (function) – Function of a single variable which we seek to find a root of. df (function, optional) – The derivative of f. steptol (float, optional) – The routine ends if the step size, dx, between sucessive iterations satisfies abs(dx) < steptol and attemptBest is False. roottol (float, optional) – The routine ends if abs(f(x)) < roottol and attemptBest is False. maxIter (int, optional) – The routine ends after maxIter iterations. attemptBest (bool, optional) – If True then routine ends if the error of the previous iteration, x0, was at least as good as the current iteration, x, in the sense that abs(f(x)) >= abs(f(x0)) and the previous iteration satisfied either abs(dx0) < steptol or abs(f(x0)) < roottol. In this case the previous iteration is returned as the approximation of the root. verbose (bool, optional) – Print x, dx and f(x) at each step of the iteration. callback (function, optional) – After each iteration callback(x, dx, f(x), iteration) will be called where ‘x’ is the current iteration of the estimated root, ‘dx’ is the step size between the previous and current ‘x’ and ‘iteration’ the number of iterations that have been taken. If the callback function evaluates to True then the routine will end.
  Returns: | An approximation for a root of f. If the rootfinding was unsucessful then None will be returned instead.
  Return type: | complex

`cxroots.IterativeMethods.` `muller`(x1, x2, x3, f, steptol=1e-12, roottol=1e-12, maxIter=20, attemptBest=False, verbose=False, callback=None)

  A wrapper for mpmath’s implementation of Muller’s method.

  Parameters: | x1 (float or complex) – An initial point for iteration, should be close to a root of f. x2 (float or complex) – An initial point for iteration, should be close to a root of f. Should not equal x1. x3 (float or complex) – An initial point for iteration, should be close to a root of f. Should not equal x1 or x2. f (function) – Function of a single variable which we seek to find a root of. steptol (float, optional) – The routine ends if the step size, dx, between sucessive iterations satisfies abs(dx) < steptol and attemptBest is False. roottol (float, optional) – The routine ends if abs(f(x)) < roottol and attemptBest is False. maxIter (int, optional) – The routine ends after maxIter iterations. attemptBest (bool, optional) – If True then routine ends if the error of the previous iteration, x0, was at least as good as the current iteration, x, in the sense that abs(f(x)) >= abs(f(x0)) and the previous iteration satisfied either abs(dx0) < steptol or abs(f(x0)) < roottol. In this case the previous iteration is returned as the approximation of the root. verbose (bool, optional) – Print x, dx and f(x) at each step of the iteration. callback (function, optional) – After each iteration callback(x, dx, f(x), iteration) will be called where ‘x’ is the current iteration of the estimated root, ‘dx’ is the step size between the previous and current ‘x’ and ‘iteration’ the number of iterations that have been taken. If the callback function evaluates to True then the routine will end.
  Returns: | complex – The approximation to a root of f. float – abs(f(x)) where x is the final approximation for the root of f.

`cxroots.IterativeMethods.` `newton`(x0, f, df, steptol=1e-12, roottol=1e-12, maxIter=20, attemptBest=False, verbose=False, callback=None)

  Find an approximation to a point xf such that f(xf)=0 for a scalar function f using Newton-Raphson iteration starting at the point x0.

  Parameters: | x0 (float or complex) – Initial point for Newton iteration, should be as close as possible to a root of f f (function) – Function of a single variable which we seek to find a root of. df (function) – Function of a single variable, df(x), providing the derivative of the function f(x) at the point x steptol (float, optional) – The routine ends if the step size, dx, between sucessive iterations satisfies abs(dx) < steptol and attemptBest is False. roottol (float, optional) – The routine ends if abs(f(x)) < roottol and attemptBest is False. maxIter (int, optional) – The routine ends after maxIter iterations. attemptBest (bool, optional) – If True then routine ends if the error of the previous iteration, x0, was at least as good as the current iteration, x, in the sense that abs(f(x)) >= abs(f(x0)) and the previous iteration satisfied either abs(dx0) < steptol or abs(f(x0)) < roottol. In this case the previous iteration is returned as the approximation of the root. verbose (bool, optional) – Print x, dx and f(x) at each step of the iteration. callback (function, optional) – After each iteration callback(x, dx, f(x), iteration) will be called where ‘x’ is the current iteration of the estimated root, ‘dx’ is the step size between the previous and current ‘x’ and ‘iteration’ the number of iterations that have been taken. If the callback function evaluates to True then the routine will end.
  Returns: | complex – The approximation to a root of f. float – abs(f(x)) where x is the final approximation for the root of f.