For the Newton-Raphson Method, I'm asked to write a loop to call the function until it has converged so that the values of x(n) and x(n+1) differ by less than a small number e=10^-8, however, I am not quite sure how to create this loop.
Here's my code so far
def newton_step(f, fp, x0):
return x0-(f(x0)/fp(x0))
import numpy as np
def f(x):
return x**3 + x**2 +2
def fp(x):
return 3*x**2 + 2*x
x = newton_step(f, fp, (x0))
count = 0 #to count the number of iterations required to satisfy the condition
while (x0 - x) <= 10**-8:
x0 = newton_step(f, fp, (x0))
count += 1
print(x0, x)