Solving permutation/combination example with MATLAB
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all,
I would like to write a MATLAB function to model a problem:
There are eight boxes, each box containing 8 balls labeled 1 to 8. If I draw one ball from each box, what are all possible combinations of 8 balls for each trial?
One easy combination (out of many) is: 1 1 1 1 1 1 1 1 What is the total number of combinations and what are the sequence of numbers for each?
Extending this idea one step further, what if I draw two balls from each box? One random example would be: [1 2] [2 3] [4 5] [7 8] [7 2] [3 6] [3 9] [3 5]
What if drawing three balls, four balls, etc. from each run?
For the limiting case of drawing 8 balls, the total number of combination is one. [1 2 3 4 5 6 7 8] [1 2 3 4 5 6 7 8] ....... [1 2 3 4 5 6 7 8]
Any help/hint on how this can be implemented efficiently in MATLAB? Thank you.
0 commentaires
Réponse acceptée
Jos (10584)
le 15 Fév 2014
hints
(1) start with 1 box with M balls, drawing n balls from it. This will give you the set S(n). Take a look at NCHOOSEK
(2) when drawing from K boxes, you can treat these boxes independently. To obtain all possible combinations of K sets you have to obtain the cartesian product of these K sets S(n). Take a look at ALLCOMB ( you can download here: <http://www.mathworks.com/matlabcentral/fileexchange/10064-allcomb> )
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices 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!