📄 baseball.m
字号:
%baseball.m/created by PJNahin for "Duelling Idiots"(10/16/98)
%This m-file calculates and plots (as a function of p) the ratio
%of the probabilities of a team winning at least 81p games out of
%81 games to the probability of winning at least 162p games out
%of 162 games, where p is the probability of winning any individual
%game.
%
%
res=input('Resolution of p = ')
clear x
clear ratio
for p=res:res:1-res
if 81*p==floor(81*p) %is 81p an integer? if yes then s81=81*p;
s81=81*p; %if no, use floor to round DOWN to nearest
else %integer and add one (e.g., "at least 17.3
s81=floor(81*p)+1; %games" means "at least 18 games).
end
if 162*p==floor(162*p) %ditto for s162;
s162=162*p;
else
s162=floor(162*p)+1;
end
sumnum=0; %form the numerator sum;
for k=s81:81
bc=binomial(81,k); %See Problem 6;
sumnum=sumnum+bc*(p^k)*((1-p)^(81-k));
end
sumden=0; %form the denominator sum;
for k=s162:162
bc=binomial(162,k);
sumden=sumden+bc*(p^k)*((1-p)^(162-k));
end
index=round(p/res);
index %display current value on screen
%to prevent boredom!
ratio(index)=sumnum/sumden;
x(index)=p;
end
plot(x,ratio)
grid
title('Fig.7.1-Ratio of Probabilities of Winning At Least np Games Out of n, n=81/np=162')
xlabel('p, probability of winning any individual game')
ylabel('ratio')
figure(1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -