function plot_poly ( )

%******************************************************************************%
%
%% plot_poly plots a 7th degree polynomial over a short range.
%
%  Discussion:
%
%    The effects of roundoff error are severe.
%
%    p(x) = ( x - 1 )^7
%
%  Modified:
%
%    31 August 2019
%
%  Author:
%
%    Original MATLAB version by Cleve Moler.
%    Modifications by John Burkardt.
%
%  Reference:
%
%    Cleve Moler,
%    Numerical Computing with MATLAB,
%    SIAM, 2004,
%    ISBN13: 978-0-898716-60-3,
%    LC: QA297.M625,
%    ebook: http://www.mathworks.com/moler/chapters.html
%
  xmin = -1.0;
  xmax = +3.0;

  for i = 1 : 10

    xstep = ( xmax - xmin ) / 100;
    x = xmin : xstep : xmax;
    y1 = x.^7 - 7*x.^6 + 21*x.^5 - 35*x.^4 + 35*x.^3 - 21*x.^2 + 7*x - 1;
    y2 = ((((((x - 7).*x + 21).*x - 35).*x + 35).*x - 21).*x + 7).*x - 1;
    y3 = ( x - 1 ).^7;
    clf ( );
    hold ( 'on' );
    plot ( x, y1, 'r-', 'linewidth', 5 )
    plot ( x, y2, 'g-', 'linewidth', 3 )
    plot ( x, y3, 'b-', 'linewidth', 1 )
    hold ( 'off' );
    xlabel ( '<-- x -->' )
    ylabel ( '<-- p(x) -->' )
    label = sprintf ( '%g < x < %g', xmin, xmax );
    title ( {
      'red: p_1(x)=x^7 - 7x^6 + 21x^5 - 35x^4 + 35x^3 - 21x^2 + 7x - 1', ...
      'green: p_2(x)=((((((x - 7)*x + 21)*x - 35)*x + 35)*x - 21)*x + 7)*x - 1', ...
      'blue: p_3(x)=(x-1)^7', label });
    grid ( 'on' )
    pause ( 5 );
    xmax = 1.0 + ( xmax - 1.0 ) / 2.0;
    xmin = 1.0 - ( 1.0 - xmin ) / 2.0;
  end

  filename = 'plot_poly.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

