I can calculate the root of a function using Newtons Method by subtracting the old x-value from the new one and checking for the convergence criterion. Is there a way of doing it when given a closed interval, e.g
Given a function and the interval [a,b] = [0.1, 3.0], the convergence criterion will be calculated by checking if [3.0 - 0.1] < 0.000001, i.e [b-a] < 0.000001.
The code I provided is calculating the convergence criterion using the x-values. I'm trying to figure out if there is a way I can use the interval instead of the x-values.
from math import *
x = 1.0 #initial value
for j in range(1, 101):
xnew = (x**2 + cos(x)**2 -4*x)/(2*(x - cos(x)*sin(x) -2))
if abs(xnew - x) < 0.000001:
break
x = xnew
print('Root = %0.6f ' % xnew)
print('Number of iterations = %d' % j)