solving nonlinear algebraic equations - - - - adjusting slightly to gives division by zerothe approximations computed by newton' method become - - - - + the division by zero is caused by :  because tanh is to machine precisionand then xd tanh / becomes zero in the denominator in newton' method the underlying problemleading to the division by zero in the above exampleis that newton' method divergesthe approximations move further and further away from if it had not been for the division by zerothe condition in the while loop would always be true and the loop would run forever divergence of newton' method occasionally happensand the remedy is to abort the method when maximum number of iterations is reached another disadvantage of the naive_newton function is that it calls the xfunction twice as many times as necessary this extra work is of no concern when xis fast to evaluatebut in large-scale industrial softwareone call to xmight take hours or daysand then removing unnecessary calls is important the solution in our function is to store the call (xin variable (f_valueand reuse the value instead of making new call (xto summarizewe want to write an improved function for implementing newton' method where we avoid division by zero allow maximum number of iterations avoid the extra evaluation of xa more robust and efficient version of the functioninserted in complete program newtons_method py for solving is listed below def newton(fdfdxxeps)f_value (xiteration_counter while abs(f_valueeps and iteration_counter tryx float(f_value)/dfdx(