function chi_square_sample_test ( )

%*****************************************************************************80
%
%% chi_square_sample_test() tests chi_square_mean(), chi_square_sample(), chi_square_variance().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 April 2009
%
%  Author:
%
%    John Burkardt
%
  nsample = 1000;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'CHI_SQUARE_SAMPLE_TEST():\n' );
  fprintf ( 1, '  CHI_SQUARE_MEAN() computes the Chi Square mean;\n' );
  fprintf ( 1, '  CHI_SQUARE_SAMPLE() samples the Chi Square distribution;\n' );
  fprintf ( 1, '  CHI_SQUARE_VARIANCE() computes the Chi Square variance.\n' );

  a = 10.0;

  check = chi_square_check ( a );

  if ( ~check );
    fprintf ( 1, '\n' );
    fprintf ( 1, 'CHI_SQUARE_SAMPLE_TEST - Fatal error!\n' );
    fprintf ( 1, '  The parameters are not legal.\n' );
    return
  end

  xmean = chi_square_mean ( a );
  variance = chi_square_variance ( a );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  PDF parameter A = %14g\n', a );
  fprintf ( 1, '  PDF mean =        %14g\n', xmean );
  fprintf ( 1, '  PDF variance =    %14g\n', variance );
  
  for i = 1 : nsample
    x(i) = chi_square_sample ( a );
  end

  xmean = mean ( x );
  variance = r8vec_variance ( nsample, x );
  xmax = max ( x );
  xmin = min ( x );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Sample size =     %6d\n', nsample );
  fprintf ( 1, '  Sample mean =     %14g\n', xmean );
  fprintf ( 1, '  Sample variance = %14g\n', variance );
  fprintf ( 1, '  Sample maximum =  %14g\n', xmax );
  fprintf ( 1, '  Sample minimum =  %14g\n', xmin );

  return
end
