Reputation: 11270
How to resolve this simple formula in Matlab?
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
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