function [ root, iteration_info ] = bisection( f, a, b, eps )
% Arguments:
%  [a, b] - interval, a < b
%  f      - continuous function defined on [a, b], f(a) and f(b) have opposite signs
%  eps    - max error
% Returns:
%  root          - found root
%  iteration_info - matrix of size (number_of_iterations)x5; row layout: [iteration, a, c, b, c - a]

iteration = 0;
iteration_info = [];
while true
  iteration = iteration + 1;
  c = (a + b) / 2;
  iteration_info(iteration, :) = [iteration, a, c , b, c - a];
  
  if c - a <= eps
    break
  end
  
  if f(a) * f(c) < 0
    b = c;
  else
    a = c;
  end
end
root  = c;
end

format short g
[result, info] = bisection(@(x)(x+log(2*x)), 0.2, 0.75, 0.00005)