function ellipsoid_monte_carlo_test03 ( )

%*****************************************************************************80
%
%% ellipsoid_monte_carlo_test03() uses ellipsoid_sample().
%
%  Discussion:
%
%    The region is a 3D ellipse centered at (1,2,3).
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 August 2014
%
%  Author:
%
%    John Burkardt
%
  m = 3;

  a = [ ...
    9.0, 6.0, 3.0; ...
    6.0, 5.0, 4.0; ...
    3.0, 4.0, 9.0 ]';
  e_test = [ ...
    0, 0, 0; ...
    1, 0, 0; ...
    0, 1, 0; ...
    0, 0, 1; ...
    2, 0, 0; ...
    0, 2, 2; ...
    0, 0, 3 ]';
  r = 0.5;
  v = [ 1.0, 2.0, 3.0 ]';

  fprintf ( 1, '\n' );
  fprintf ( 1, 'ellipsoid_monte_carlo_test03():\n' );
  fprintf ( 1, '  ellipsoid_sample() estimates integrals\n' );
  fprintf ( 1, '  in a 3D ellipse (x-v)'' * A * (x-v) <= r^2.\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Ellipsoid radius R = %g\n', r );
  r8vec_print ( m, v, '  Ellipsoid center V:' )
  r8mat_print ( m, m, a, '  Ellipsoid matrix A:' )

  volume = ellipsoid_volume ( m, a, v, r );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Ellipsoid volume = %g\n', volume );

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

  n = 1;

  while ( n <= 65536 )

    x = ellipsoid_sample ( m, n, a, v, r );

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

    for j = 1 : 7

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

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

      result = volume * sum ( value(1:n) ) / n;

      fprintf ( 1, '  %14.6g', result );

    end

    fprintf ( 1, '\n' );

    n = 2 * n;

  end

  return
end
