フィルターのクリア

simulation problem/Project Euler #307

1 回表示 (過去 30 日間)
Jan
Jan 2015 年 5 月 14 日
編集済み: Jan 2015 年 5 月 14 日
I have written a short simulation program (two short functions) for this problem
k defects are randomly distributed amongst n integrated-circuit chips produced by a factory (any number of defects may be found on a chip and each defect is independent of the other defects).
Let p( k,n) represent the probability that there is a chip with at least 3 defects. For instance p(3,7) ≈ 0.0204081633.
I've written the simulation program as given in https://github.com/jfredett/euler/blob/master/c/problem-307/README-307.mkd
However,it gives 2 orders smaller probability for the toy example p(3,7),see the bottom of the email. WHY??I do not see any problem either with the approach nor with my application. Here are the two functions:
function [succ,E]=recur(k,n)
E=zeros(1,n);
succ=0;
while k>0
for i=1:n
if rand>0.5 E(i)=E(i)+1;k=k-1;end;
end;
if max(E)>2 succ=1;E,return,end;
end
return
--------------------------------------------
function res=recur2(k,n,m)
suc=0;
for i=1:m
suc=suc+recur(k,n);end;
res=suc/m
return
--------------------------------------------
recur2(3,7,1000000)
ans =
2.3900e-04

回答 (0 件)

カテゴリ

Help Center および File ExchangeMonte-Carlo についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by