How to generate realisations from two sets

8 ビュー (過去 30 日間)
mohamed Faraj
mohamed Faraj 2019 年 8 月 28 日
編集済み: the cyclist 2019 年 8 月 28 日
I have two sets,e.g., S1={1,2,3,4} and S2={1,2,3,4,5}. I want to pick up 2 numbers randomly from S1 and 3 numbers from S2. Note that the order of the 2 or 3 picked numbers is not important. Theoretically, the probability that a number will appear in both sets is 2/4*3/5=6/20 (Am I correct?). I want to prove this using matlab by generating a large number of realizations and check the distribution.

回答 (1 件)

the cyclist
the cyclist 2019 年 8 月 28 日
編集済み: the cyclist 2019 年 8 月 28 日
L1 = length(S1);
N1 = 2;
S1(randperm(L1,N1))
will choose N1 numbers (in this case, 2) from S1. You can choose similarly from S2.
Regarding your probability estimate ...
You cannot say in general that the probability of appearing in both sets is 6/20. What if S1 and S2 have no numbers in common?

Community Treasure Hunt

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

Start Hunting!

Translated by