function value = quad_parfor ( n )

%*****************************************************************************80
%
%% quad_parfor() demonstrates MATLAB's PARFOR command for parallel programming.
%
%  Discussion:
%
%    This function estimates an integral using the composite trapezoidal rule.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    26 March 2010
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of points to use.
%
%  Output:
%
%    real VALUE, the estimate for the integral.
%
  a = 0.0;
  b = 1.0;

  value = 0.0;
  h = ( b - a ) / ( n - 1 );

  parfor i = 1 : n

    x = ( ( n - i ) * a + ( i - 1 ) * b ) / ( n - 1 );

    fx = 4.0 ./ ( 1 + x.^2 );

    if ( i == 1 )
      value = value + 0.5 * fx * h
    elseif ( i < n )
      value = value +       fx * h;
    elseif ( i == n )
      value = value + 0.5 * fx * h;
    end

  end

  return
end

