% Math 5610 HW 2
%
% Problem 3 - B&F 2.3.5 and 2.3.7
%
% This is sample code - will not run without modifications
%
% YOUR NAME
tol = 1e-4; maxit=20;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fprintf('**** B&F 2.3.5 a and 2.3.7 a\n')

% We are using a function handle for both f and f'
f      = @(x) x^3 - 2*x^2 -5;
fprime = @(x) 3*x^2 - 4*x;

% compute root with Newton's and Secant methods
xnewt = newton(f,fprime,4,tol,maxit);
xsec  = secant(f,1,4,tol,maxit);

% display results
fprintf('%13s %13s\n','newton','secant');
for i=1:max([length(xnewt),length(xsec)]),
 if (i<=length(xnewt) && i <= length(xsec) )
  fprintf('%13.8f %13.8f\n',xnewt(i),xsec(i));
 else 
  if (i>length(xnewt))
   fprintf('%13s %13.8f\n',' ',xsec(i));
  else 
   fprintf('%13.8f %13s\n',xnewt(i),' ');
  end;
 end;
end;



