function variance = i4vec_variance ( n, x )

%*****************************************************************************80
%
%% i4vec_variance() returns the variance of an I4VEC.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    02 September 2004
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of entries in the vector.
%
%    integer X(N), the vector whose variance is desired.
%
%  Output:
%
%    real VARIANCE, the variance of the vector entries.
%
  if ( n < 2 )

    variance = 0.0;

  else

    mean = sum ( x(1:n) ) / n;

    variance = sum ( ( x(1:n) - mean ).^2 );

    variance = variance / ( n - 1 );

  end 

  return
end
