function uniform_variance ( )

%*****************************************************************************80
%
%% UNIFORM_VARIANCE computes the mean and variance of uniform samples.
%
%  Discussion:
%
%    Let X be N samples from the uniform distribution on [0,1].
%
%    The mean of the PDF is 0.5, and the variance is 1/12.
%
%    The sample mean is the average value of X.
%
%    The sample second moment is the average value of X^2.
%
%    The sample variance is the average value of the square of the difference
%    between each sample value and the mean.
%
%    The sample variance can be computed as the difference between the
%    sample second moment and the square of the sample mean.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    13 February 2013
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'UNIFORM_VARIANCE\n' );
  fprintf ( 1, '  Compute mean and variance of uniform samples.\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  N  E(X)  E(X^2)  V1  V2  V3  V4\n' );
  fprintf ( 1, '\n' );

  n = 1;
  for nlog10 = 0 : 6
    x = rand ( n, 1 );
    mu = sum ( x ) / n;
    mu2 = sum ( x.^2 ) / n;
    v1 = sum ( ( x - mu ).^2 ) / n;
    v2 = mu2 - mu^2;
    v3 = sum ( ( x - mu ).^2 ) / ( n - 1 );
    v4 = sum ( ( x - 0.5 ).^2 ) / n;
    fprintf ( 1, '  %8d  %12g  %12g  %12g  %12g  %12g  %12g\n', n, mu, mu2, v1, v2, v3, v4 );
    n = n * 10;
  end

  return
end
