马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
Count = 1000;
Limit = 7.8794;
RejectTime = 0;
while(Count > 0)
A = binornd(1,0.4,100,1);
B = randsrc(100,1,[1 2 3;0.09 0.42 0.49]);
C = [A, B];
r0 = 0; r1 = 0; r2 = 0;
s0 = 0; s1 = 0; s2 = 0;
n0 = 0; n1 = 0; n2 = 0;
r = 0; s = 0; n = 0;
SUM = 0; SUM1 = 0; SUM2 = 0; SUM3 = 0;
for(i = 1:1:100)
if ((C(i,1)==0)&(C(i,2)==1))
r0 = r0+1;
else if((C(i,1)==0)&(C(i,2)==2))
r1 = r1+1;
else if((C(i,1)==0)&(C(i,2)==3))
r2 = r2+1;
else if((C(i,1)==1)&(C(i,2)==1))
s0 = s0+1;
else if((C(i,1)==1)&(C(i,2)==2))
s1 = s1+1;
else ((C(i,1)==1)&(C(i,2)==3))
s2 = s2+1;
end
end
end
end
end
end
clc;
n0 = r0 + s0;
n1 = r1 + s1;
n2 = r2 + s2;
r = r0 + r1 + r2;
s = s0 + s1 + s2;
n = n0 + n1 + n2;
R(1) = r0; R(2) = r1; R(3) = r2;
S(1) = s0; S(2) = s1; S(3) = s2;
N(1) = n0; N(2) = n1; N(3) = n2;
for(j = 0:1:2)
X(0) = 0; X(1) = 0.5; X(2) = 1;
P(0) = r0./r; P(1) = r1./r; P(2) = r2./r;
Q(0) = s0./s; Q(1) = s1./s; Q(2) = s2./s;
T(0) = n0./n; T(1) = n1./n; T(2) = n2./n;
SUM1 = SUM1 + ((X(j)*(P(j)-Q(j)))^2);
SUM2 = SUM2 + (X(j)^2*T(j));
SUM3 = SUM3 + ((X(j)*T(j))^2);
SUM = (r*s*SUM1./n*(SUM2-SUM3));
end
Count = Count - 1;
if(SUM > Limit)
RejectTime = RejectTime + 1;
end
end
RejectTime
RejectTime/1000; |