class RootFinder: # This class provides methods for solving one-dimensional problems # of the kind: find a root x of f(x) = 0. def __init__(self,kernel,algorithm): self.kernel = kernel self.algo = algorithm def setKernel(self,kernel): self.kernel = kernel def solveFor0(self,accuracy): if self.algo=='NR': return self.NewtonRaphson(accuracy); print 'Cannot solve for kernel = 0 in algorithm ',self.algo,';' print 'algorithm is not implemented.' return None def NewtonRaphson(self,accuracy): # An implementation of the Newton-Raphson method to # solve f(x) = 0. # Trial solutions are produced with help of the function # and its first derivative. The iterative procedure should # stop if |x_{i+1}-x_i|/|x_{i+1}+x_i| < 2 accuracy # Fix this. return 0.