function chain_test ( )

%*****************************************************************************80
%
%% chain_test() tests chain().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 January 2022
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'chain_test():\n' );
  fprintf ( 1, '  chain() estimates the extinction probability of a chain letter.\n' );
  fprintf ( 1, '  A chain letter asks the recipient to make C copies\n' );
  fprintf ( 1, '  and send them on.  Suppose that, with probability P,\n' );
  fprintf ( 1, '  any recipient ignores the request, and with probability\n' );
  fprintf ( 1, '  any recipient complies with it.\n' );
  fprintf ( 1, '  Estimate the probability E that the chain\n' );
  fprintf ( 1, '  letter will terminate.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Need to solve E = p + ( 1 - p ) * E^c )\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  C    P    E\n' );

  for c = 1 : 5
    fprintf ( 1, '\n' );
    for i = 1 : 2 : 9
      p = i / 10;
      e = chain ( c, p );
      fprintf ( 1, '  %d  %g  %g\n', c, p, e );
    end
  end

  return
end

