function hw053 ( f )

  n = length ( f );
  m = sum ( f );
  p = f / m;
  c = cumsum ( p );
%
%  Simulate M times.
%
  bin = zeros ( 1, n );
  for j = 1 : m
    r = rand ( );
    for i = 1 : n
      if ( r < c(i) )
        bin(i) = bin(i) + 1;
        break;
      end
    end
  end
%
  clf 

  figure ( 1 );
  bar ( 1:n, f );
  grid on
  xlabel ( '<-- Outcomes -->' );
  ylabel ( '<-- Frequency -->' );
  title ( 'Original observed data', 'Fontsize', 24 );
  print ( '-djpeg', 'hw053_observed.jpg' );

  figure ( 2 ) 
  bar ( 1:n, bin );
  grid on
  xlabel ( '<-- Outcomes -->' );
  ylabel ( '<-- Frequency -->' );
  title ( 'Simulated data', 'Fontsize', 24 );
  print ( '-djpeg', 'hw053_simulated.jpg' );

  return
end

