clc
clear

f = @(x) (x^2 - 5);
xl = input('Enter first approximation: ');
xu = input('Enter second approximation: ');
acc = input('Enter accuracy: ');

while(f(xl) * f(xu)) > 0
    xl = input('Enter first approx value again: ');
    xu = input('Enter second approx value again: ');
end

itr = 0;
while(abs(xu - xl) > acc)
    xm = xu - (f(xu) * (xu - xl)) / (f(xu) - f(xl));
    itr = itr + 1;
    
    if (f(xl) * f(xm)) < 0
        xu = xm;
    else
        xl = xm;
    end
end

xm
itr