% Comparison of three root finding methods
% ========================================
%   
% 1. Compute 20 iterates for each method

x(1) = 1;
y(1) = 1;
z(1) = 1;

for n = 1:19
  x(n+1) = newton_root ("g", "dg", x(1), 0, n);
  y(n+1) = secant_root ("g", 2, y(1), 0, n);
  z(n+1) = bisection_root ("g", -0.5, z(1), n);
end

% 2. Plot sequence index vs. the log of the error
%
% First, compute the "true" limit with a large number of iterations 

x_error = abs(x);
y_error = abs(y);
z_error = abs(z);

nn = [1:20]; % Vector with the "x" coordinates for plotting 

semilogy (nn, x_error, ';Method A;', ...
	  nn, y_error, ';Method B;', ...
	  nn, z_error, ';Method C;');

gset term postscript eps monochrome;
gset output "history-g.eps"
replot
gset term x11
