function z ( )

%*****************************************************************************80
%
%% Z uses a histogram to approximate the distribution of X/(X-Y).
%
%  Discussion:
%
%    This m-file simulates the random variable Z=X/(X-Y),
%    where X and Y are independent and uniform from 0 to 1.
%    The output is a histogram of Z.
%
%  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, 'Z:\n' );
  fprintf ( 1, '  This m-file simulates the random variable Z=X/(X-Y),\n' );
  fprintf ( 1, '  where X and Y are independent and uniform from 0 to 1.\n' );
  fprintf ( 1, '  The output is a histogram of Z.\n' );

  index = 10000;

  while ( index > 0 )
    X = rand ( );
    Y = rand ( );
    Z = X / ( X - Y );
    if ( abs ( Z ) < 3 )
      vector(index) = Z;
      index = index - 1;
    end
  end
%
%  Graphics.
%
  clf
  x = -3 : .05 : 3;
  hist ( vector, x )
  title('Fig.12.4 - Histogram of Z=X/(X-Y)')
  xlabel('z, in bins of width 0.05')
  ylabel('number of numbers in each bin')
  print ( '-dpng', 'z.png' );

  return
end
