function value = energy ( )

%*****************************************************************************80
%
%% energy() assigns an energy to an emitted particle.
%
%  Discussion:
%
%    The energy E is in the range [EMIN,EMAX], with distribution
%    const/sqrt(energy).
%
%    An inverse function approach is used to compute this.
%
%    The energies are measured in MeV.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    02 September 2012
%
%  Author:
%
%    Original FORTRAN77 version by Kahaner, Moler, Nash.
%    MATLAB version by John Burkardt.
%
%  Reference:
%
%    David Kahaner, Cleve Moler, Steven Nash,
%    Numerical Methods and Software,
%    Prentice Hall, 1989,
%    ISBN: 0-13-627258-4,
%    LC: TA345.K34.
%
%  Output:
%
%    real VALUE, a randomly chosen energy that is
%    distributed as described above.
%
%  Local:
%
%    real EMIN, EMAX, the minimum and maximum energies.
%
  emax = 2.5;
  emin = 1.0E-03;

  u = rand ( 1, 1 );

  c = 1.0 / ( 2.0 * ( sqrt ( emax ) - sqrt ( emin ) ) );

  value = ( u / ( 2.0 * c ) + sqrt ( emin ) );
  value = value * value;

  return
end

