balls.m
来自「一些常被用于教学或者参考的概率论的实例的源代码」· M 代码 · 共 27 行
M
27 行
%balls.m/created by PJNahin for "Duelling Idiots"(12/19/98)
%This m-file calculates two quantities; (1) the average number of
%drawings (with replacement) of numbered balls before a repetition
%occurs, and (2) the largest number of drawings that still allows
%the probability there is NOT a repetition is still greater than 1/2.
%
%
n=input('How many balls are in the urn? ')
F=1/n;
E=F;
j=1;
NF=F*(n-j)/n;
while NF>0
F=NF;
j=j+1;
NF=F*(n-j)/n;
E=E+j*j*F;
end
E
j=0;
Prod=1;
while Prod > .5
Prod=Prod*((n-j)/n);
j=j+1;
end
T=j-1;
T
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?