fprintf ( '\n' );
fprintf ( 'HAWAII:\n' );
fprintf ( '  Consider four islands of Hawaii: Oahu, Kauai, Maui, and Lanai\' );
fprintf ( '  Suppose that, every year, some people stay on their home island\n' );
fprintf ( '  and others move to another island.\n' );
fprintf ( '  For every island, we know the percentages that stay, and that\n' );
fprintf ( '  move.\n' );
fprintf ( '\n' );
fprintf ( '  Given the populations in 2000, simulate the yearly changes in population.\n' ); 
fprintf ( '\n' );
fprintf ( '  Examine the behavior over a long enough period to notice any patterns.\n' );
fprintf ( '\n' );

fprintf ( '\n' );
fprintf ( '  Year        Oahu       Kauai        Maui       Lanai       Total\n' );
fprintf ( '  ----  ----------  ----------  ----------  ----------  ----------\n' );
fprintf ( '\n' );

m = 6;
oa = zeros ( 1, m );
ka = zeros ( 1, m );
ma = zeros ( 1, m );
la = zeros ( 1, m );

for i = 1 : m

  year = 1999 + i;

  if ( year == 2000 )
    oa(i) = 1000000;
    ka(i) = 1000000;
    ma(i) = 1000000;
    la(i) = 1000000;
  else
    [ oa(i), ka(i), ma(i), la(i) ] = hawaii_update ( oa(i-1), ka(i-1), ma(i-1), la(i-1) );
  end

  fprintf ( '  %4d  %10.0f  %10.0f  %10.0f  %10.0f  %10.0f\n', year, oa(i), ka(i), ma(i), la(i), oa(i) + ka(i) + ma(i) + la(i) );

end

plot ( 1999+1:1999+m, oa, 1999+1:1999+m, ka,  1999+1:1999+m, ma, 1999+1:1999+m, la,'Linewidth', 3 );
grid on
xlabel ( '<-- Year -->' );
ylabel ( '<-- Hawaiian Island Populations -->' );
title ( 'Hawaii population model', 'Fontsize', 24 );
legend ( 'Oahu', 'Kauai', 'Maui', 'Lanai' );
print ( '-djpeg', 'hawaii.jpg' );     

function [ oa, ka, ma, la ] = hawaii_update ( oa, ka, ma, la )
%
%% HAWAII_UPDATE updates the Hawaiian island populations for one year.
%
  oa_old = oa;
  ka_old = ka;
  ma_old = ma;
  la_old = la;

  oa = 0.32 * oa_old + 0.17 * ka_old + 0.11 * ma_old + 0.46 * la_old;
  ka = 0.18 * oa_old + 0.43 * ka_old + 0.32 * ma_old + 0.33 * la_old;
  ma = 0.27 * oa_old + 0.22 * ka_old + 0.39 * ma_old + 0.14 * la_old;
  la = 0.23 * oa_old + 0.18 * ka_old + 0.18 * ma_old + 0.07 * la_old;

  return
end

