我对处理偏置硬币的MATLAB问题有疑问。假设我想模拟一个偏向硬币,并且有可能根据以下数据集p ={0.5,0.4,0.3,0.2, 0.1}
调高头部。
我如何从这个数据集中任意选择一个假想的硬币,并确定它是否在MATLAB中是无偏的,因为 N N 100 到 1000 ,步长 100 。由于我对Matlab的了解有限,我希望得到一些指导来帮助这个项目。我发现这个网站有一些指针http://www.wikihow.com/Simulate-a-Fair-Coin-Toss-With-a-Biased-Coin
我用于翻转硬币两次的matlab代码
function side = simulateOneToss
% Make two tosses (outcomes 0 and 1 could stand for heads and tails)
twoTosses = round(rand(1,2));
% If outcome is not HT or TH (both of which sum to 1), try again.
while sum(twoTosses) ~= 1
twoTosses = round(rand(1,2));
end
% Take first of the two tosses as the answer.
side = twoTosses(1);
我的第一个问题代码
function outcome = mysim(p, N)
P = cumsum(p);
u = rand(1, N);
outcome = zeros(1, N); % A blank array for holding the outcomes `enter code here`
for n=100:100:N,
h = find(u(n)<P, 1 );
outcome(n) = h;
end