function cc ( )

%*****************************************************************************80
%
%% CC computes the correlation between elements of a random vector.
%
%  Discussion:
%
%    This program generates a random vector, X, of length
%    20,009 and then calculates the correlation coefficient
%    X(n) and X(n+j) for j = 0,1,2,...,9.
%
%  Modified:
%
%    29 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'CC:\n' );
  fprintf ( 1, '  This program generates a random vector, X, of length\n' );
  fprintf ( 1, '  20,009 and then calculates the correlation coefficient\n' );
  fprintf ( 1, '  X(n) and X(n+j) for j = 0,1,2,...,9.\n' );

  for i = 1 : 20009
    X(i) = rand ( );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  J  Cor(X(i),X(i+j))\n' );
  fprintf ( 1, '\n' );

  for j = 0 : 9
    summation = 0;
    for i = 1 : 20000
      summation = summation + X(i) * X(i+j);
    end
    coefficient = ( 12 * summation / 20000 ) - 3;
    fprintf ( 1, '  %2d  %g\n', j, coefficient );
  end

  return
end
