function x = english_word_length_cdf_inv ( cdf )

%*****************************************************************************80
%
%% english_word_length_cdf_inv() inverts the English Word Length CDF.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    26 August 2006
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Henry Kucera, Winthrop Francis,
%    Computational Analysis of Present-Day American English,
%    Brown University Press, 1967.
%
%  Input:
%
%    real CDF, the value of the CDF.
%    0.0 <= CDF <= 1.0.
%
%  Output:
%
%    integer X, the corresponding word length for which
%    CDF(X-1) < CDF <= CDF(X)
%
  word_length_max = 27;

  pdf_vec = [ ...
    0.03160, ...
    0.16975, ...
    0.21192, ...
    0.15678, ...
    0.10852, ...
    0.08524, ...
    0.07724, ...
    0.05623, ...
    0.04032, ...
    0.02766, ...
    0.01582, ...
    0.00917, ...
    0.00483, ...
    0.00262, ...
    0.00099, ...
    0.00050, ...
    0.00027, ...
    0.00022, ...
    0.00011, ...
    0.00006, ...
    0.00005, ...
    0.00002, ...
    0.00001, ...
    0.00001, ...
    0.00001, ...
    0.00001, ...
    0.00001 ];
  pdf_sum = 0.99997;

  if ( cdf < 0.0 || 1.0 < cdf )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'ENGLISH_WORD_LENGTH_CDF_INV - Fatal error!\n' );
    fprintf ( 1, '  CDF < 0 or 1 < CDF.\n' );
    error ( 'ENGLISH_WORD_LENGTH_CDF_INV - Fatal error!' );
  end

  cum = 0.0;

  for j = 1 : word_length_max

    cum = cum + pdf_vec(j);

    if ( cdf <= cum / pdf_sum )
      x = j;
      return
    end

  end

  x = word_length_max;
  
  return
end
