function [x, itr] = falsepos(f, x0, x1, acc)
% FALSEPOS  finds the approx. root of a given function using method of false position.
% Inputs:   f -- an anonymous function
%           x0, x1 -- start and end bound of the solution
%           acc -- accuracy of the approx. solution
% Outputs:  x -- the approx. solution
%           itr -- number of iteration performed to get the solution

if (f(x0) * f(x1)) > 0
    error("Invalid bounds. f(x0) and f(x1) produces result of same sign!")
end

itr = 0;
disp(["itr", "x", "y"])
while true
    itr = itr + 1;

    x = x0 - f(x0) * ((x1 - x0) / (f(x1) - f(x0)));
    y = f(x);
    disp([itr, x, y])

    if abs(y) < acc
        break;
    elseif (f(x0) * y) < 0
        x1 = x;
    else
        x0 = x;
    end
end