function simplex_monte_carlo_test03 ( )

%*****************************************************************************80
%
%% simplex_monte_carlo_test03() estimates integrals in 3D.
%
%  Discussion:
%
%    Integration is over a general simplex.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    02 March 2017
%
%  Author:
%
%    John Burkardt
%
  m = 3;
  e_test = [ ...
    0, 0, 0; ...
    1, 0, 0; ...
    0, 1, 0; ...
    0, 0, 1; ...
    2, 0, 0; ...
    1, 1, 0; ...
    1, 0, 1; ...
    0, 2, 0; ...
    0, 1, 1; ...
    0, 0, 2 ]';
  t = [ ...
    1.0, 0.0, 0.0;
    2.0, 0.0, 0.0;
    1.0, 2.0, 0.0;
    1.0, 0.0, 3.0 ]';

  fprintf ( 1, '\n' );
  fprintf ( 1, 'TEST03\n' );
  fprintf ( 1, '  SIMPLEX_GENERAL_SAMPLE computes a Monte Carlo estimate of\n' );
  fprintf ( 1, '  an integral over the interior of a general simplex in 3D.\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Simplex vertices:\n' );
  fprintf ( 1, '\n' );
  for j = 1 : 4
    for i = 1 : 3
      fprintf ( 1, '%14.6g', t(i,j) );
    end
    fprintf ( 1, '\n' );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '         N        1               X               Y ' );
  fprintf ( 1, '              Z               X^2              XY             XZ' );
  fprintf ( 1, '              Y^2             YZ               Z^2\n' );
  fprintf ( 1, '\n' );

  n = 1;

  while ( n <= 65536 )

    x = simplex_general_sample ( m, n, t );

    fprintf ( 1, '  %8d', n );

    for j = 1 : 10

      e(1:m) = e_test(1:m,j);

      value = monomial_value ( m, n, e, x );

      result = simplex_general_volume ( m, t ) * sum ( value(1:n) ) / n;
      fprintf ( 1, '  %14.6g', result );

    end

    fprintf ( 1, '\n' );

    n = 2 * n;

  end

  return
end
