function term = chain ( c, p )

%*****************************************************************************80
%
%% chain() plots the probability that a chain letter will terminate.
%
%  Discussion:
%
%    A chain letter asks the recipient to make C copies and send them on.
%    Suppose each recipient complies, with probability p.  What is the
%    likelihood that the chain letter will eventually terminate?
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    07 May 2019
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Will You Be Alive 10 Years From Now?,
%    Princeton, 2014,
%    ISBN: 978-0691156804,
%    LC: QA273.25.N344
%
%  Input:
%
%    real c: the number of copies that each recipient is asked to make.
%
%    real p: the probability that a recipient will NOT make c copies and 
%    send them on.
%
%  Output:
%
%    real term: the probability that this chain of letters will terminate.
%

%
%  Suppress informative messages from fsolve.
%  This feature does not exist in Octave!
%
% options = optimoptions ( 'fsolve', 'Display', 'off' );

  term0 = 0.5;
% term = fsolve ( @(term) term - p - ( 1.0 - p ) * term^c, term0, options );
  term = fsolve ( @(term) term - p - ( 1.0 - p ) * term^c, term0 );

  return
end

