function [ mu, var ] = rectangle_distance_stats ( n, a, b )

%*****************************************************************************80
%
%% rectangle_distance_stats() estimates rectangle distance statistics.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 May 2023
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer n: the number of pairs of sample points to use.
%
%    real a, b: the length of the two sides.
%
%  Output:
%
%    real mu, var: the estimated mean and variance of the
%    distance between two random points in the rectangle.
%
  p = rectangle_sample ( n, a, b );
  q = rectangle_sample ( n, a, b );
  t = zeros ( n, 1 );
  for i = 1 : n
    t(i) = norm ( p(i,1:2) - q(i,1:2) );
  end

  mu = sum ( t(1:n) ) / n;
  if ( 1 < n )
    var = sum ( ( t(1:n) - mu ) .^ 2 ) / ( n - 1 );
  else
    var = 0.0;
  end

  return
end
