« JNS | 最新のページに戻る | JNP »
■ JNS昨日の続き
Matlabコードは以下の通り。適当。Ver.6.5でモンテカルロの繰り返しは10万回でelapsed_time =128 sec。
n=100000; % no of iteration
T=20; % no of total trials
ch=2; % no of choices
MAXIMUMRUN=zeros(n,1);
for i=1:n,
Q=[];for j=1:T,Q1=randperm(ch);Q(j)=Q1(1);end; % Q: question
A=[];for j=1:T,A1=randperm(ch);A(j)=A1(1);end; % A: answer
CRR=Q-A;CRRno=find(CRR==0); % correct answer when CRR==0
% calculation of maxmum run of CRR==0
maxrun=0;maxr=0;
for k=1:length(CRRno)
for m=1:length(CRRno)-k, if CRRno(k)+m==CRRno(k+m), maxr=m+1;end; end
if maxrun < maxr,maxrun=maxr;end
end
MAXIMUMRUN(i)=maxrun;
end
[ [1:T]' hist(MAXIMUMRUN,1:T)'/n]