Agent Based Model :Simple segregation model
6 ビュー (過去 30 日間)
古いコメントを表示
Hello guys, Can I just ask u how to modify my original Model in the following way? 1.Specify that the there are initially more psychologists than economists. 2.Only allow adjacent neighbours to switch
Below is the coding for my original Coding %Orignal Model %Schelling-style model clear all
%first we set up a world with randomly scattered economists and psychologists
nside=50; %the number of agents on each side of the matrix randworld=rand(nside,nside); %Or could use round(rand(nside,nside)) world=randworld>.5; %say psychologist=0; economist=1;
colormap([0 1 0; 1 0 0]);% sets psychs as green , econs as red
numsadecons=100; numsadpsychs=100; %give these temp high values just to satisfy the while condition
while (numsadecons>50) && (numsadpsychs>50)
%first calcuate number of econs surrounding each agent
A=circshift(world,1); B=circshift(world,-1);
C=circshift(world',1)'; D=circshift(world',-1)';
necon=A+B+C+D; %now necon has numbers of econ neighbours for each person in world
%Now determine the unhappy econs
sadecons=world.*((world.*necon)<3); %an econ wants to be around at least 3 econs
%Now determine the unhappy psychs
sadpsychs=abs(world-1).*((abs(world-1).*necon)>1); %a psych is unhappy around > 1 econ
numsadecons=sum(sum(sadecons)); numsadpsychs=sum(sum(sadpsychs));
%now choose a random sad econ and change to be a psych:
[r,c]=find(sadecons); %get the row and col indices of all sad econs
index=ceil(rand*numsadecons); %choose a random sad econ
world(r(index),c(index))=0; %change the econ to a psych
%now choose a random sad psych and change to be an econ:
[r,c]=find(sadpsychs); %get the row and col indices of all sad psychs
index=ceil(rand*numsadpsychs); %choose a random sad psych
world(r(index),c(index))=1; %change the psych to an econ
imagesc(world) %draw a colourmap
pause(0.01) %pause for 0.01 second
end
2 件のコメント
yawen deng
2018 年 12 月 5 日
Have you solved this problem?Seems I have the same problem and don't know how to solve it.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Eigenvalue Problems についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!