% hw054

m = 20;
a = zeros ( 1, m );
b = zeros ( 1, m );
c = zeros ( 1, m );

p = [ 0.90, 0.02, 0.04;
      0.05, 0.68, 0.40;
      0.05, 0.30, 0.56];

for i = 1 : m

  if ( i == 1 )
    a(i) = 0;
    b(i) = 300;
    c(i) = 500;
  else
    a(i) = p(1,1) * a(i-1) + p(1,2) * b(i-1) + p(1,3) * c(i-1);
    b(i) = p(2,1) * a(i-1) + p(2,2) * b(i-1) + p(2,3) * c(i-1);
    c(i) = p(3,1) * a(i-1) + p(3,2) * b(i-1) + p(3,3) * c(i-1);
  end

  fprintf ( '  %4d  %10.0f  %10.0f  %10.0f\n', i, a(i), b(i), c(i) );

end

plot ( 1:m, a, 1:m, b,  1:m, c,'Linewidth', 3 );
grid on
xlabel ( '<-- Month -->' );
ylabel ( '<-- Population -->' );
title ( 'Abel, Babel, Cable Dorms', 'Fontsize', 24 );
legend ( 'A', 'B', 'C' );
print ( '-djpeg', 'hw054.jpg' );     

