% function to plot result of Newton's method
% p = polynomial in MATLAB vector format
% a = size of box around origin to draw
% n = number of subdivisions of box

 function  plot_newton(p,a,n)
   tic;
   all_roots=roots(p);
   delta=abs(2*a)/n;
   clear save_root;
   save_root=zeros(n);
   for k=1:n
      for j=1:n
         z=(-abs(a)+2*abs(a)*j/n)+1i*(-abs(a)+2*abs(a)*k/n);
         [y,iter]=poly_newton(p,z);
          if isnan(y)
              save_root(k,j)=0;
          else
              [m,root_num]=min(abs(all_roots-y));
             save_root(k,j)=root_num;
          end
      end
      k;
   end
   all_roots;
   num_roots=length(all_roots);
   save_root; 
   x=[-a,a];
   y=[-a,a];
   setc=flipud(jet(num_roots+1));
   %colormap(jet(depth))
   %colormap(hsv(depth))
   %colormap(gray(depth))
   %colormap(flipud(winter(depth)))
   setc(1,:)=zeros(1,3);
   colormap(setc)
   image(x,y,save_root+1,'CDataMapping','scaled')
   hold on
   scatter(real(all_roots),imag(all_roots),'ro','Filled')
   %image(x,y,save_root,'CDataMapping','scaled')
   %axis image
   %colormap(flipud(jet(length(all_roots))))
   toc;
return;

