Hi! So I'm not exactly an expert with Python, nor am I with Calculus, yet I tried to code a program that would work to solve Newtons Method. Nevertheless, even if the code seems alright, the answers that I am getting are not even close to the correct, checked answer. I believe it might be due to the fact that the program isn't taking into account the iterations and the change of the value of x when iterating. I was wondering if someone could please help me out with this? I really cannot see what the problem is and how to fix it. Thank you in advance!:
def newtonsmethod(ftn, fprime, x0, n):
def f(x):
return eval(ftn)
def df(x):
return eval(fprime)
x=x0
for iterations in range(1,n+1):
x = x - (f(x)/df(x))
return x
n=100
ans=newtonsmethod("x**-2", "-2*x**-3", 1.4, 100)
print (f"The root was found to be at {ans} after {n} iterations")```