{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

schelling2 - Bail out after 300 iterations or when A=B This...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function A=schelling2(M,N,f1,f0) % The parameters f1 and f0 measure discontent. Example: if f1=.8 and f0=.6, % then a red is discontent if more than 80% of its neighbors are blue, and a % blue is discontent if more than 60% of its neighbors are red. A=round(rand(M,N)); % Random zero-one matrix of size MxN colormap([0 0 1; 1 0 0 ]); imagesc(A);axis('equal');axis off;pause(1) test=1; k=1; while (test==1 & k<300);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % Bail out after 300 iterations, or when A=B. This typically indicates % "cycling". This value can be incrased. B=sw2(A,f1,f0); % The next iteration. imagesc(B);axis('equal');axis off;pause(1/20) % You may replace pause(1/20) pause for step-by-step control Atest=A-B; % Are A and B the same? test=any(Atest(:)); % is test=0 ? A=B; % If test=1, then reassign A k=k+1; end...
View Full Document

{[ snackBarMessage ]}