So i did my code in the following way shown below; however, the way that my codes decided to stop the loop and output the root is by comparing if F(xr)==0 or not; however, i want to add another term which is the "approximated error" term that is to compare with a desired maximum error. So, once the Ea <= Emax, the loop is ended. The Ea should be calculated as (current approximation - previous approximation)/ current approximation; however, this is the part i do not know how to code. Could you help me with it? Any help would be really appreciated!! Thanks.
function root= bisection(fun, lb, ub,iter_max)
disp('termination type 1: there is no root within bracket')
for i= 1: iter_max
if i >= iter_max
disp('termination type 0: algorithm terminated due to maximum interations')
disp('this is the root')
fprintf('The iterations taken is: %d', i)