# Thread: Matlab - Distribution of money - HELP

1. ## Matlab - Distribution of money - HELP

Hi,
Here is the problem:
Suppose that N agents can exchange money in pairs. They are all assigned the same amount of money m0, and are then allowed to interact.
At each step, a pair of agent i and j with money mi and mj is randomly chosen and a transaction takes place.
After a random reassignment of money, we assume:
mi'=E(mi+mj)
mj'=(1-E)(mi+mj)
Where E is a randon number between 0 and 1.
(this reassignment ensures no debts after the transaction).

QUESTION:
Using Matlab, simulate this model and determine the distribution of money among the agents after the system has relaxed to an equilibrium state.
Chose: N=100
m0=1000

If someone could help me on this, it would be grealty appreciated.

2. ## further study of the code

So here is my code so far:

clear all;
M=1000*ones(100,1); %100 agents with 1000$initially. T=input('enter a value for T:'); %the number of times that 2 agents are randomly picked and are allowed to interact. for i=1:1:T %loop from i=1 to i=T. x=randi([1 100],1); %agent 1 picked at step i. y=randi([1 100],1); %agent 2 picked at step i. R=rand; %generates a random number between 0 and 1 if x==y; y=randi([1 100],1); %in case picking twice the same agent end P=M(x); Q=M(y); M(x)=R.*(P+Q); %such reassignment of money ensures no dept after transaction. M(y)=(1-R).*(P+Q); disp(' ') end for j=1:1:size(M); fprintf('%5.0f\t%5.0f\n',j,M(j)); end Mf=sum(M,1); % Mf = total amount of money (~=100,000$)
fprintf('Total amount of money:\n%5.0f\t%5.0f\n',Mf);
C=sort(M);
D=C(81:1:100);
disp(' ')
E=sum(D); % E = total amount of money among the 20 richest agents.
fprintf('Amount of money among the 20 richest agents:\n%5.0f\t%5.0f\n',E);

How can i plot the distribution of money after T pickings ?
I'd guess a gaussian dist, what are the command in this case?
where should I place it within the code?