1

I want to figure out a program for calculating Newton's method after the user inputs the equation they would like to figure out and the number of iterations they want to know. This program is in python.

So far, I just have a program to calculate one equation i just don't know how to get the user to enter the equation and number of iterations they want to see the value for.

def f1(x):
    return x**3-(2.*x)-5.

def derivative_f1(x):
    return (3*x**2)-2.

def Newton(f, df, x, tol):

    while True:
        x1 = x - (f(x)/df(x))

        t = abs(x1-x)

        if t < tol:
            break
        x = x1

    return x

initial = 2

print(Newton(f1,derivative_f1,initial,0.000001))
Conor
  • 39
  • 1
  • 9

0 Answers0