function bernstein_poly_ab_approx_display ( )

%*****************************************************************************80
%
%% BERNSTEIN_POLY_AB_APPROX_DISPLAY displays Bernstein approximants.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    28 January 2016
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'BERNSTEIN_POLY_AB_APPROX_DISPLAY\n' );
  fprintf ( 1, '  BERNSTEIN_POLY_AB_APPROX evaluates the Bernstein polynomial\n' );
  fprintf ( 1, '  approximant to a function F(X).\n' );
%
%  Sin(x)
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  This program displays the sequence of approximants\n' );
  fprintf ( 1, '  to y=sin(x) over the interval [1,3]\n' );

  a = 1.0;
  b = 3.0;

  for n = 0 : 20
%
%  Generate data values.
%
    xdata = ( linspace ( a, b, n + 1 ) )';
    ydata = sin ( xdata );
%
%  Compare the true function and the approximant.
%
    nval = 501;
    xval = ( linspace ( a, b, nval ) )';
    yval = bernstein_poly_ab_approx ( n, a, b, ydata, nval, xval );
    ytrue = sin ( xval );

    clf
    plot ( ...
      xval, yval, 'b-', ...
      xval, ytrue, 'r-', ...
      xdata, ydata, 'r.', 'Markersize', 30 );
    grid
    xlabel ( '<---X--->' );
    ylabel ( '<---Y--->' );
    title ( sprintf ( 'Bernstein Approximant n = %d', n ) );

    fprintf ( 1, 'Bernstein approximant n = %d\n', n );

    pause ( 2 )

  end
%
%  Heaviside.
%
  a = -1.0;
  b = +1.0;

  for n = 0 : 20
%
%  Generate data values.
%
    xdata = ( linspace ( a, b, n + 1 ) )';
    ydata = heaviside ( xdata );
%
%  Compare the true function and the approximant.
%
    nval = 501;
    xval = ( linspace ( a, b, nval ) )';
    yval = bernstein_poly_ab_approx ( n, a, b, ydata, nval, xval );
    ytrue = heaviside ( xval );

    clf
    plot ( ...
      xval, yval, 'b-', ...
      xval, ytrue, 'r-', ...
      xdata, ydata, 'r.', 'Markersize', 30 );
    grid
    xlabel ( '<---X--->' );
    ylabel ( '<---Y--->' );
    title ( sprintf ( 'Bernstein Approximant n = %d', n ) );

    fprintf ( 1, 'Bernstein approximant n = %d\n', n );

    pause ( 2 )

  end

  return
end
