% mexico_population_plot.m
%  Model Mexico population.
%
%  Year  Population
%  1950  25,791,017
%  1960  34,923,129
%  1970  48,225,238
%  1980  66,846,833
%  1990  81,249,645
%  2000  97,483,412
%  2010 113,580,528
%
rate = input ( '  Enter model growth rate, like 0.03: ' );
year_start = 1950;
year_end = input ( '  What year after 1950 should model stop at: ' );

pop_list = [];

for year = year_start : year_end

  if ( year == year_start )
    pop = 25791017;
    pop_list = [ pop_list, pop ];
  else
    pop_old = pop;
    pop = ( 1.0 + rate ) * pop_old;
    pop_list = [ pop_list, pop ];
  end

  fprintf ( '  %d  %d\n', year, round ( pop ) )
end
%
%  The plot uses thin lines that can be hard to see.
%  Here, I asked for a line of thickness "3".
%
plot ( year_start:year_end, pop_list, 'linewidth', 3 );
grid;
title ( 'Mexico Exponential Population Model' );
xlabel ( '<-- Year -->' );
ylabel ( '<-- Population -->' );
%
%  We can add the actual data on top of the previous plot.
%  We do this by the "hold on" command (I want to add more to this plot)
%  We set up the data list.
%  Then we plot, but use the "r." option, which just shows data as red dots,
%  not connected lines.
%  The dots can be small, so I made them bigger with "markersize".
hold on
pop2_list = [ 25791017, 34923129, 48225238, 66846833, 81249645, 97483412, 113580528 ];
plot ( 1950:10:2010,        pop2_list, 'r.', 'markersize', 25 );
hold off
