function paradox ( a )

#*****************************************************************************80
#
## paradox() looks at the average lifetime of a complex system.
#
#  Discussion:
#
#    A simple system has an average lifetime of A.
#    For reliability, a complex system is constructed of three simple systems.
#    The complex system will only fail if at least two of the simple systems fail.
#    What is the average lifetime of the complex system?
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    08 February 2023
#
#  Author:
#
#    Original MATLAB version by Paul Nahin.
#    This version by John Burkardt.
#
#  Reference:
#
#    Paul Nahin,
#    Dueling Idiots and Other Probability Puzzlers,
#    Princeton, 2012,
#    ISBN: 978-0691155005.
#
#  Input:
#
#    real A, the average lifetime of a single system.
#
  print ( '' )
  print ( 'paradox():' )
  print ( '  A simple system has an average lifetime of A.' )
  print ( '  For reliability, a complex system is constructed of three simple systems.' )
  print ( '  The complex system will only fail if at least two of the simple systems fail.' )
  print ( '  What is the average lifetime of the complex system?' )
  print ( '' )
  print ( '  Present the results graphically.' )

  a = 1 / a

  for n = 1 : 200
    s(n) = 1 - exp ( - a * n )
    r(n) = s(n) * s(n) * ( 3 - 2 * s(n) )
  end
#
#  Graphics.
#
  clf ( )
  t = 1 : 200
  plot ( t, s, '-', t, r, '.' )
  ylabel ( 'probability of failure by time t' )
  xlabel ( 'time t, in arbitrary units' )
  grid ( 'on' )
  title ( 'Average Lifetime of a system is 100' )
  legend ( 'system','SYSTEM' )
  filename = 'paradox.png'
  plt.savefig ( filename )
  print ( '  Graphics saved as "' + filename + '"' )
  plt.close ( )

  return
end
