Package Scientific :: Package Functions :: Module FindRoot
[frames] | no frames]

Module FindRoot

Newton-Raphson for numerical root finding

Example:

   >>>from Scientific.Functions.FindRoot import newtonRaphson
   >>>from Scientific.N import pi, sin, cos
   >>>def func(x):
   >>>    return (2*x*cos(x) - sin(x))*cos(x) - x + pi/4.0
   >>>newtonRaphson(func, 0.0, 1.0, 1.0e-12)

   yields 0.952847864655.
Functions
float
newtonRaphson(function, lox, hix, xacc)
Newton-Raphson algorithm for root finding.
Function Details

newtonRaphson(function, lox, hix, xacc)

 

Newton-Raphson algorithm for root finding. The algorithm used is a safe version of Newton-Raphson (see page 366 of Numerical Recipes in C, 2ed).

Parameters:
  • function (callable) - function of one numerical variable that uses only those operations that are defined for DerivVar objects in the module Scientific.Functions.FirstDerivatives
  • lox (float) - lower limit of the search interval
  • hix (C[{loat}) - upper limit of the search interval
  • xacc (float) - requested absolute precision of the root
Returns: float
a root of function between lox and hix
Raises:
  • ValueError - if function(lox) and function(hix) have the same sign, or if there is no convergence after 500 iterations