Kate
Kate

Reputation: 109

probabilities combinations

I faced a problem while writing a code in Matlab that calculates sum of products of all possible combinations of n numbers taken from a vector with length m. It is similar to the task that you will drag exactly n different balls out of the bag with m balls (order doesn't matter).

example: m = 5, n = 3 then i need to calculate sum of 10 summands

thanks for your time

Upvotes: 1

Views: 145

Answers (1)

Clement J.
Clement J.

Reputation: 3032

You should use nchoosek.

m=5;
n=3;
s=sum(nchoosek(1:m,n), 2);

Upvotes: 3

Related Questions