simulation problem/Project Euler #307
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Monte-Carlo dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!