function bulb ( switch_num )

%*****************************************************************************80
%
%% bulb() analyzes the light bulb problem.
%
%  Discussion:
%
%    This code calculates and plots the probability of a bulb,
%    wired in series/parallel with sheets of switches, glowing.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 May 2019
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
%  Input:
%
%    integer switch_num: the number of switches.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'bulb():\n' );
  fprintf ( 1, '  Calculate and plot the probability of a bulb turning on,,\n' );
  fprintf ( 1, '  wired in series/parallel with sheets of %d switches.\n', switch_num );

  for p = 1 : 200
    r = p / 200;
    P1(p) = ( 1 - ( 1 - r ^ switch_num ) ^ switch_num ) ^ switch_num;
    P2(p) = 1 - ( ( 1 - r ^ switch_num ) ^ ( switch_num * switch_num ) );
  end
%
%  Graphics.
%
  clf ( );
  r = 0.005 : 0.005 : 1.0;
  hold ( 'on' );
    plot ( r, P1, '-', 'linewidth', 3 );
    plot ( r, P2, '.' );
  hold ( 'off' );
  grid ( 'on' );
  title ( '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 );

  return
end
