function legendre_interpolant_bumpy ( n )

%*****************************************************************************80
%
%% legendre_interpolant_bumpy uses n Legendre polynomials to interpolate bumpy(x).
%
%  Input:
%
%    integer n: the number of interpolation points.
%
  a = 0.0;
  b = 3.0;
  x = linspace ( a, b, n );
  x = x';
  y = bumpy(x);

  A = zeros ( n, n );
  for j = 1 : n
    A(:,j) = legendre_value ( j - 1, x );
  end

  c = A \ y;
%
%  Display the function as a blue line, and samples of the interpolant as red dots.
%
  clf ( );
  hold ( 'on' );
  xplot = linspace ( a, b, n );
  xplot = xplot';
  yplot = zeros ( n, 1 );
  for j = 1 : n
    p = legendre_value ( j - 1, xplot );
    yplot = yplot + c(j) * p;
  end
  plot ( xplot, yplot, 'r.', 'markersize', 25 );
  xplot = linspace ( a, b, 101 );
  plot ( xplot, bumpy(xplot), 'b-' )
  hold ( 'off' )
  grid ( 'on' );
  label = sprintf ( '%d degree Legendre interpolant (red) to bumpy(x) (blue)', n-1 );
  title ( label );

  return
end

