function mortality_expected_plot ()

%*****************************************************************************80
%
%% mortality_expected_plot() plots expected mortality.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 February 2019
%
%  Author:
%
%    John Burkardt
%

%
%  Get the data.
%
  [ age, total, male, female ] = mortality_count ( );
%
%  Get sums for normalization.
%
  n = length ( age );

  et = zeros ( n, 1 );
  em = zeros ( n, 1 );
  ef = zeros ( n, 1 );
  for i = 1 : n
    if ( 0 < sum ( total(i:n) ) )
      et(i) = ( age(i:n)' * total(i:n) ) / sum ( total(i:n) );
    end
    if ( 0 < sum ( male(i:n) ) )
      em(i) = ( age(i:n)' * male(i:n) ) / sum ( male(i:n) );
    end
    if ( 0 < sum ( female(i:n) ) )
      ef(i) = ( age(i:n)' * female(i:n) ) / sum ( female(i:n) );
    end
  end
%
%  Make the plot.
%
  figure ( );
  clf ( );
  hold ( 'on' );
    plot ( age, et, 'k-', 'linewidth', 3 );
    plot ( age, em, 'b-', 'linewidth', 3 );
    plot ( age, ef, 'r-', 'linewidth', 3 );
    plot ( age, age, 'g-', 'linewidth', 3 );
  hold ( 'off' );
  xlabel ( '<-- Age at death -->' );
  ylabel ( '<-- Number of deaths -->' );
  title ( 'Total life expectancy by age, in 2007' );
  grid ( 'on' );
  legend ( 'Combined', 'Male', 'Female', 'Age if you die now', 'Location', 'North' );

  filename = 'mortality_expected.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  close ( );

  return
end
