function q = hat_integral ( n )

%*****************************************************************************80
%
%% hat_integral estimates an integral involving a hat function.
%
%  Input:
%
%    integer n: the order (number of points) of the Gauss rule.
%
%  Output:
%
%    real q: the integral estimate.
%

%
%  The interval [a,b] has been divided up into m subintervals.
%
  a = 0.0;
  b = 2.0 * pi;
  m = 8;
  x = linspace ( a, b, m + 1 );
%
%  Estimate I(f*phi_i,a,b) when phi_i(x) is the hat function
%  between x(i-1) and x(i+1).  Choose i=7 for this example:
%    
  i = 7;
  [ xg1, wg1 ] = gauss_ab ( n, x(i-1), x(i) );
  [ xg2, wg2 ] = gauss_ab ( n, x(i), x(i+1) );
  
  q = wg1' * ( f(xg1) .* hat ( x(i-1), x(i), x(i+1), xg1 ) ) ...
    + wg2' * ( f(xg2) .* hat ( x(i-1), x(i), x(i+1), xg2 ) );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of subintervals of [a,b] = %d\n', m );
  fprintf ( 1, '  Number of Gauss points in rule = %d\n', n );
  fprintf ( 1, '  Estimated integral is %20.16g\n', q );

  return
end
function value = f ( x )
  value = sin ( x );
  return
end

