function p=steffensen_table(g,p0,tol,max_iterations) % Steffensen's method: See section 2.5. % This version prints the iterations in a table. fprintf(' n | p_0 | p_2 | p_2 | p-hat \n'); fprintf('---------------------------------------------------------------\n'); for i=1:max_iterations % Store the previous iteration in p0. p1 = g(p0); p2 = g(p1); p = p0 - (p1-p0)^2 / (p2 - 2*p1 + p0); fprintf('%2d | %+12.8f | %+12.8f | %+12.8f | %+12.8f\n', i, p0, p1, p2, p); if abs(p-p0)