% MATH 5610
% HW 3 Problem 1
% B&F 2.4.1 and 2.4.3 PART B

% SAMPLE CODE, assumes the following have been implemented
%   - newton.m      : Newton's method
%   - newton_mult.m : Modified Newton's method for multiple roots
tol = 1e-5; maxit = 40;

%% Part B
x0 = -1.5; % initial guess
f  = @(x) cos(x+sqrt(2)) + x*(x/2+sqrt(2));
fp = @(x) -sin(x+sqrt(2)) + (x/2+sqrt(2)) + x/2;
fpp= @(x) -cos(x+sqrt(2)) + 1;
xs1 = newton(f,fp,x0,tol,maxit);
xs2 = newton_mult(f,fp,fpp,x0,tol,maxit);
fprintf('Part b: NM=%13.8f in %4d iter MNM=%13.8f in %4d iter\n',...
       xs1(end),length(xs1),xs2(end),length(xs2));

% Here is the output you should be getting:
%
%  >> prob1_sample                     
%  Part b: NM=  -1.41445659 in   23 iter MNM=  -1.41424162 in    3 iter

