function x = bisection(a, b, n) c = f(a); d = f(b); if c * d > 0 error('The function has same sign on both the sides') end for i = 1 : n x = (a + b) / 2; if f(a) * f(x) < 0 b = x; elseif f(b) * f(x) < 0 a = x; end end end