% NOTE: In order to run this file on Octave or MATLAB
% type 'california' at the prompt

%================================================================
% 	THE PROBLEM
%================================================================
% Let us suppose that the world is divided into three
% entities with respect to the population
% - California
% - Arizona
% - The rest of the world
%
% Let us denote the populations of respective states by C, A, and R
% respectively.
%
% Let us assume that every year the following happens:
%
%  .005 of the people in California move to Arizona
%  .01  of the poeple in California move to the Rest of the World
%  .002 of the people in Arizona move to California
%  .007 of the people in Arizona move to the Rest of the World
%  .001 of the people in the Rest of the World move to California
%  .001 of the poeple in the rest of the World move to Arizona
%================================================================


%
% Transition matrix for the Californa, Arizona and RestOfThe World
%


A = [
     .985 .002 .001;
     .005 .991 .001;
     .01 .007 .998
     ];

%
% The transition matrix is supposed to be a probability
% matrix, i.e. the entries are >= 0 and the sum of 
% each column must be 1. The way to check it is this:
% [1, 1, 1,..., 1]* A must be [1, 1, 1, ..., 1].
% For our matrix, this is the calculation:
%

[1,1,1]*A - [1,1,1]

% The result of the above must be [0, 0, 0]!!!

%
% Let us suppose that the initial populations are given by
% the vector p = [C; A; R]
%

p = [30; 4; 100]

%
% The population p1 after one year obeys the rule
%          p1 = A*p
%

p1 = A * p

% The population after 100 years is

p100 = A^100 * p

% The population after 1000 years is

p1000 = A^1000 * p

%
% Powers of A^n converge when A is a probability matrix
% which is transitive, i.e. A^n >0 for some n.
% Our matrix obeys this requirement.
%
