iterative Newton's method
<p>I have got this code to solve Newton's method for a given polynomial and initial guess value. I want to turn into an iterative process which Newton's method actually is. The program should keeping running till the output value "x_n" becomes constant. And that final value of x_n is the actual root. Also, while using this method in my algorithm it should always produce a positive root between 0 and 1. So does converting the negative output (root) into a positive number would make any difference? Thank you. </p>

<pre><code>import copy

poly = [[-0.25,3], [0.375,2], [-0.375,1], [-3.1,0]]

def poly_diff(poly):
    """ Differentiate a polynomial. """

    newlist = copy.deepcopy(poly)

    for term in newlist:
        term[0] *= term[1]
        term[1] -= 1

    return newlist

def poly_apply(poly, x):
    """ Apply a value to a polynomial. """

    sum = 0.0 

    for term in poly:
        sum += term[0] * (x ** term[1])

    return sum

def poly_root(poly):
    """ Returns a root of the polynomial"""

    poly_d = poly_diff(poly)
    x = float(raw_input("Enter initial guess:"))

    x_n = x - (float(poly_apply(poly, x)) / poly_apply(poly_d, x))

    print x_n

if __name__ == "__main__" :
    poly_root(poly)
</code></pre>
