Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python bisection method

def bisection(f, a, b, eps):
  if f(a) * f(b) >= 0:
    raise BaseException("Wrong interval!")
  if a > b:
    a, b = b, a
  n = 0
  x = (a + b) / 2
  while b - a >= 2*eps:
    if f(x) == 0:
      return x, n
    elif f(a) * f(x) < 0:
      b = x
    else:
      a = x
    x  = (a + b) / 2
    n += 1
  return x, n
Source by courses.fit.cvut.cz #
 
PREVIOUS NEXT
Tagged: #python #bisection #method
ADD COMMENT
Topic
Name
2+9 =