Consider one function
f1 = @(x) cos(x)-x;
x1r = fzero(f1, 0);
You can do it like this
n = 0:50;
x1n = zeros(size(n)); % all solutions for f1
for i = 1:numel(x1n)
x1n(i) = bisectionMethod(f1, 0, 1, n(i));
end
err = abs(x1n-z1r);
A more efficient approach is to modify bisectionMethod() function such that it returns a complete vector in a single call. The above code is repeating the same calculations several times.
