function bulb ( n )

%*****************************************************************************80
%
%% BULB analyzes the light bulb problem.
%
%  Discussion:
%
%    This M file calculates and plots the probability of a bulb,
%    wired in series/parallel with sheets of switches, glowing.
%
%  Modified:
%
%    07 May 2019
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
%  Input parameters:
%
%    Input, integer N, the number of switches.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'BULB:\n' );
  fprintf ( 1, '  BULB calculates and plots the probability of a bulb,\n' );
  fprintf ( 1, '  wired in series/parallel with sheets of switches, glowing.\n' );

  for p = 1 : 200
    r = p / 200;
    P1(p) = ( 1 - ( 1 - r ^ n )^ n ) ^ n;
    P2(p) = 1 - ( ( 1 - r ^ n ) ^ ( n * n ) );
  end
%
%  Graphics.
%
  clf
  r = .005 : .005 : 1;
  plot(r,P1,'-',r,P2,'.')
  grid ( 'on' );
  title('Fig.3.4-Solid Line for Series Sheets, Dots for Parallel Sheets')
  xlabel('probability, p, an individual switch is closed')
  ylabel('probability bulb glows, P(10,p)')
  filename = 'bulb.png';
  print ( '-dpng', filename )
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  pause ( 5 )

  return
end
