% initial point x0 x0 = -.5; x1 = x0 - f(x0)/df(x0); ep = 10^-6; % the error tolerance max_iterate = 10^4; % the maximum of the iteration steps it_count=1; %it_count is the iteration steps, starting with 1 while ( error >= ep && it_count < max_iterate ) it_count = it_count + 1; x0 = x1; x1 = x0 - f(x0)/df(x0); end it_count format long e root1 = x1 clear all % initial point x0 x0 = .5; x1 = x0 - f(x0)/df(x0); ep = 10^-8; % the error tolerance max_iterate = 10^4; % the maximum of the iteration steps it_count=1; %it_count is the iteration steps, starting with 1 while ( abs(x1-x0) >= ep && it_count < max_iterate ) it_count = it_count + 1; x0 = x1; x1 = x0 - f(x0)/df(x0); end it_count format long e root2 = x1