Eugene
Eugene

Reputation: 11270

How to resolve this formula in Matlab ( sum of combinations)

How to resolve this simple formula in Matlab?

enter image description here

This is sum of combinations. There is function nchoosek to get number of combinations (n,k).

nchoosek(k+m, i) will find this for an i. But how to find for all ranges of i?

So, the only way to resolve this, is to write loop? Or I can do it inline - with matlab functions?

Upvotes: 0

Views: 783

Answers (1)

PengOne
PengOne

Reputation: 48398

If the sum goes from 0 to m+k, then the answer is 2^(m+k), no iteration required. If the sum is from 1 to m+k, then the answer is 2^(m+k)-1.

If you're insistent, then the for loop looks like this:

s = 0;
for i=1:qu
  s = s + nchoosek(m+k,i);
end

The function nchoosek can take a vector as the first argument, but not as the second.

Upvotes: 2

Related Questions