|
发表于 2012-7-17 16:52:00
|
显示全部楼层
Re:一个有趣的问题:赌徒财富极值
既然LZ有空把答案做了出来,我就写个模拟程序来检验一下:
主要脚本:
clc;clear;
n=input('Input MoneyPower = ');
fprintf('------------Original Money is %g.\n',2^n);
p=input('Input WinChance = ');
TestTime=1000000;
AverageMaxMoney=mean(arrayfun(@(x) Gamble(n,p),ones(1,TestTime)*n));
fprintf('The Average MaxMoney with Modeling Method is %g.\n',AverageMaxMoney);
fprintf('The Average MaxMoney with Theory Method is %g.\n',2^n*(1-2*p)/(1-3*p));
模拟函数:
function MaxMoney=Gamble(OriginalMoneyPower,p)
MaxMoney=2^OriginalMoneyPower;
CurrentMoney=2^OriginalMoneyPower;
while CurrentMoney>1
if rand()<p
CurrentMoney=CurrentMoney*2;
else
CurrentMoney=CurrentMoney/2;
end
if CurrentMoney>MaxMoney
MaxMoney=CurrentMoney;
end
end
一个运行结果:
Input MoneyPower = 4
------------Original Money is 16.
Input WinChance = 0.1
The Average MaxMoney with Modeling Method is 18.2869.
The Average MaxMoney with Theory Method is 18.2857.
|
|