%localtoy.m

%to run the different simulations you need to uncomment the appropriate
%lines

players=3;
time_steps=50;
income=zeros(time_steps,players);
local_multipliers=zeros(players);

% store=zeros(1,10);
% for lm=0:0.05:0.45
% for ex=0:0.25:3   


%    lm=0.25;
% local_multipliers(1,2:3)=[lm lm];
% local_multipliers(2,[1 3])=[lm lm];
% local_multipliers(3,1:2)=[lm lm];
local_multipliers(1,2:3)=[0.4 0.42];
local_multipliers(2,[1 3])=[0.38 0.47];
local_multipliers(3,1:2)=[0.43 0.46];

   ex=5;
external_input=[ex ex ex];

income(1,:)=[28 25 36];

for t=2:time_steps

local_input=income(t-1,:)*local_multipliers;
noise=0;
income(t,:)=local_input+external_input.*((1-noise/2)+(rand(1,3)*noise));

if t==25
    local_multipliers(3,1:2)=[0.05 0.06];
    external_input(3)=40;
end

end

%store(round(lm*20+1))=income(time_steps,1);
%store(round(ex*4+1))=income(time_steps,1);
% store(round(lm*20+1),round(ex*4+1))=income(time_steps,1);

%       end;
%       end
 

figure(1)
plot(income)
xlabel('time')
ylabel('income')
title('Toy local economy for three players, change at t = 25')

figure(2)
xlabel('time')
ylabel('total income')
title('Toy local economy for three players, change at t = 25')

%surf(store);xlabel('External income');ylabel('Multiplier');zlabel('Total income')


%starting conditions don't matter
%robust under noise
%sum of lm =>1 then income does not reach equilibrium
%final equilibrium is an exponenital function of lm (at lm=0, equilibrium Y
%is 10)
%final equilibrium is a linear function of external input (cos constant,
%not multiplicative)
%draw surface!
