% Math 5610 HW 2
%
% Problem 1 - B&F 2.1.5 
%
% This is sample code - will not run without modifications
%
% YOUR NAME

% tolerance and maximum number of iterations
tol = 1e-5; maxit=30;

fprintf('***** problem B&F 2.1.5 c\n');

% Below f is a function handle. It is an object that represents a
% function. In this way we can pass it as an argument for another
% function (in this case bisect).
f = @(x) 2*x*cos(2*x) - (x+1)^2;

x1=bisect(f,-3,-2,tol,tol,maxit);
x2=bisect(f,-1,0,tol,tol,maxit);

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