function prob = ten_years ( years )

%*****************************************************************************80
%
%% ten_years() estimates whether you will be alive in 10 years.
%
%  Licensing:
%
%    This code is distributed under the MIT license. 
%
%  Modified:
%
%    12 January 2022
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Will You Be Alive 10 Years From Now?,
%    Princeton, 2014,
%    ISBN: 978-0691156804,
%    LC: QA273.25.N344
%
%  Input:
%
%    integer years: the number of years in the future, between 0 and 10.
%
%  Output:
%
%    real prob: the probability you will still be alive.
%
  if ( years < 0 || 10 < years )
    error ( 'ten_years: 0 <= years <= 10 is required!' );
  end

  phi = [ 20.3, ...
          19.5, 18.9, 18.2, 17.6, 16.9, ...
          16.2, 15.6, 15.0, 14.4, 13.8 ];

  phi_int = 0.0;
  for y = 1 : years
    phi_int = phi_int + 0.5 * ( 1.0 / phi(y) + 1.0 / phi(y+1) );
  end

  log_prob = log ( phi(1) ) - log ( phi ( years + 1 ) ) - phi_int;

  prob = exp ( log_prob );

  return
end
