
% function to apply  Newton's method  to a polynomial
% derivative is computed by this function

function [y,k] = poly_newton(p,x)
   p_prime=polyder(p);
   k = 0;
   xprev=x+1;
   while abs(x - xprev) > eps*abs(x)
      xprev = x;
      x = x - polyval(p,x)/polyval(p_prime,x);
      k = k + 1;
      if k>50
          y=NaN;
          return;
      end
   end
   y=x;
return;


