Yes, your loop is not quite right.
Notice your placement of the three lines
converge = false;
po = p_init(1);
These three lines are brfore the loops, and thus, none of these three parameters ever gets reset.
This is why your loop does not work right.
After solving the first value, p0 never gets set to the next value, and i never gets reset to 1 for the next itteration.
Also, after the loop converges on an answer, you do not display or save the answer, so you won't know what it is.
f = @(x) x^3 - x^2 - 6*x;
df = @(x) 3*x^2 - 2*x - 6;
p_init = -3:.1:4;
tol = 1e-12;
n_iter = 10;
Sol = nan(3,numel(p_init));
for j = 1:length(p_init)
Sol(1,j) = p_init(j);
p = p0-f(p0)/df(p0);
error = abs(p-p0);
if (error< tol)
Sol(2,j) = p0;
Sol(3,j) = i;
i = i+1;
p0 = p;
At the end of this "while" loop, you have matrix "sol";
Sol(1,:) is the initial guess value
Sol(2,:) is the final solution value
Sol(3,:) is the number of itterations used to get the solution.
Notice that Sol(1,j) (the initial guess) is saved before entering the "for" loop. If the loop ends without finding a solution, them Sol(2,j) and Sol(3,j) wil be "nan", so you will know that convergence was not achieved for this guess within the itteration limit (n_iter).