function example3p11 ( )

% MATLAB version of FORTRAN program for example 3.11 on pages 115 in conte/deboor
% Newton's method for finding a real zero of a certain polynomial.
% The coefficients are supplied, as is a first guess for the zero is solicited.
%
%  Reference:
%
%    Samuel Conte, Carl de Boor,
%    Elementary Numerical Analysis,
%    Third Edition,
%    SIAM, 2017,
%    ISBN: 978-1-611975-19-2.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'example3p11\n' );

  A = [-6.8 10.8 -10.8 7.4 -3.7 1]; 
  N = length(A);

% X = input('please supply a first guess for the zero:  ');
  X = 1.0;

  disp('Newton''s method for finding a real zero of a polynomial ')
  disp('    I    X                AP              APP ')
  converge = false;
  for j=1:20
    B = A(end); C = B;
    for k=N:-1:3
      B = A(k-1) + X*B; C = B + X*C;
    end
    B = A(1) + X*B;
    fprintf('   %2d  %15.7e  %15.7e %15.7e\n',[j,X,B,C])
    DELTAX = B/C;
    if abs(DELTAX)<1e-7 || abs(B)<1e-7, converge = true;  break, end
    X = X - DELTAX;  
  end
  if ~converge, disp('failed to converge in 20 iterations'), end

  return
end

