% initial points x0 and x1 x0 = -1; f0 = f(x0); x1 = 0; 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 ( abs(x1-x0) >= ep && it_count < max_iterate ) it_count = it_count + 1; f1 = f(x1); x2 = x1 - f1*(x1-x0)/(f1-f0); x0 = x1; f0 = f1; x1 = x2; end it_count format long e root1 = x1 clear all % initial points x0 and x1 x0 = 0; f0 = f(x0); x1 = 1; 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 ( abs(x1-x0) >= ep && it_count < max_iterate ) it_count = it_count + 1; f1 = f(x1); x2 = x1 - f1*(x1-x0)/(f1-f0); x0 = x1; f0 = f1; x1 = x2; end it_count format long e root2 = x1