Bisection Method Mahalakshmi R
Bisection Method Mahalakshmi R
import math
from matplotlib import pyplot as plt
import numpy as np
from datetime import datetime
today = datetime.today()
print(today.strftime("%B %d, %Y"))
iteration = 0
while (b - a) / 2 > tol and iteration < max_iter:
c = (a + b) / 2 # Midpoint
if f(c) == 0 or (b - a) / 2 < tol: # Root found or interval
is small enough
return c
elif f(a) * f(c) < 0: # Root lies between a and c
b = c
else: # Root lies between c and b
a = c
iteration += 1
# X-axis label
plt.xlabel("x")
# Y-axis label
plt.ylabel("f(x)")
Output:
Bisection Method
Mahalakshmi R