%
% This is a driver for three root finders
%
% Written by Ming Gu for Math 128A, Fall 2010
%
format long g
params.tol   = 1e-15;
params.MaxIt = 100;
%
% bisection method
%
Intv.a = 2.5;
Intv.b = 10;
%%Intv.b = 4;
[x_bisect, out_bisect]= bisect2(@myfunc5,Intv,params);
%
% fixed point
%
x0= Intv.a;
[x_fixedpoint, out_fixedpoint] = fixedpoint(@myfunc5a, x0, params);
%
% Newton's Method
%
x0= Intv.b;
%%x0= 2.5; %% method will quickly converge with this choice of x0 
[func,dfunc,x_Newton, out_Newton]=NewtonMethod(@myfunc5, @dmyfunc5, x0, params);
%
% Report results
%
fprintf('\n');
if (out_bisect.flg==0)
   disp(['Bisection succeeded.']);
   disp(['# of iterations = ',num2str(out_bisect.it), '; root = ', num2str(x_bisect(end))]);
   fx = myfunc5(x_bisect(end));
   disp(['Residual Error = ', num2str(fx)]);
   fprintf('\n');
   fprintf('\n');
else
   disp(['Bisection failed.']);
   fprintf('\n');
   fprintf('\n');
end
if (out_fixedpoint.flg==0)
   disp(['Fixedpoint succeeded.']);
   disp(['# of iterations = ',num2str(out_fixedpoint.it), '; root = ', num2str(x_fixedpoint(end))]);
   fx = myfunc5(x_fixedpoint(end));
   disp(['Residual Error = ', num2str(fx)]);
   fprintf('\n');
   fprintf('\n');
else
   disp(['Fixedpoint failed.']);
   fprintf('\n');
   fprintf('\n');
end
if (out_Newton.flg==0)
   disp(['Newton succeeded.']);
   disp(['# of iterations = ',num2str(out_Newton.it), '; root = ', num2str(x_Newton(end))]);
   fx = myfunc5(x_Newton(end));
   disp(['Residual Error = ', num2str(fx)]);
   fprintf('\n');
   fprintf('\n');
else
   disp(['Newton failed.']);
end
