The history of tolerance and corresponding x values can be stored if we treat them as vectors and in each iteration of for loop the value at that point is stored. Refer to the following code to see how it works:
function [r, k] = root_finder(f,x0,kmax,tol)
x1 = x0;
for i = 2 : kmax
r(i) = abs(feval(f,x1));
k(i) = x1;
if tol >r(i)
break;
end
x1 = x1 + 0.01;
end
end