hello all, we had this problem in the class and we asked to verify the answer using MATLAB (answer=0.13867), so I write the following code:
if true>> a= rand;b=rand;c=rand;e=rand;d=rand;x=0.251;n=0;p=0;for i=1: 10000if (a<x)a=1;elsea=0;endif (b<x)b=1;else b=0;endif (c<x)c=1;else c=0;endif (d<x)d=1;else d=0;endif (e<x)e=1;else e=0;endp = (a*b)+ (a*e*d)+(c*d)+(c*e*b);if (p>=1)n=n+1;endend;n/10000 end
and the answer appears is either 1 or 0.5, what is wrong? thanks ahead, I've to submitting it tomorrow, pls help
Best Answer