📄 tub.m
字号:
%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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -