tub.m

来自「一些常被用于教学或者参考的概率论的实例的源代码」· M 代码 · 共 38 行

M
38
字号
%tub.m/created by PJNahin for "Duelling Idiots"(2/19/99)
%This m-file computes the optimal allocation of search boats
%looking for the UNSINKABLE TUB.
%
%
ps=input('Probability a search boat finds the TUB? ');
N=input('Total number of search boats available? ');
for index=1:999
   p1=index/1000;
   p2=1-p1;
   n=(N+(log(p2/p1)/log(1-ps)))/2;
   nl=floor(n);
   nu=nl+1;
   Pl=p1*(1-(1-ps)^nl)+p2*(1-(1-ps)^(N-nl));
   Pu=p1*(1-(1-ps)^nu)+p2*(1-(1-ps)^(N-nu));
   if n>N
      n=N;
   end
   if n<0
      n=0;
   end
   if n>0&n<N
   if Pl>Pu
      n=nl;
   else
      n=nu;
   end
   end
   answer(index)=n;
end
p=.001:.001:.999;
plot(p,answer)
grid
ylabel('n, the number of search boats assigned to Island #1')
xlabel('p1, the probability the UNSINKABLE TUB is at Island #1')
title('Fig.16.3')
figure(1)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?