Math Matlab

Calculating the indices for n choose k


Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /data/1/b/1b32a628-bdcf-4151-86ff-5d5550106b39/nonconditional.com/public_html/wp-content/plugins/wp-syntax/wp-syntax.php on line 380

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /data/1/b/1b32a628-bdcf-4151-86ff-5d5550106b39/nonconditional.com/public_html/wp-content/plugins/wp-syntax/wp-syntax.php on line 380

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /data/1/b/1b32a628-bdcf-4151-86ff-5d5550106b39/nonconditional.com/public_html/wp-content/plugins/wp-syntax/wp-syntax.php on line 380

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /data/1/b/1b32a628-bdcf-4151-86ff-5d5550106b39/nonconditional.com/public_html/wp-content/plugins/wp-syntax/wp-syntax.php on line 380

So if you want to calculate n choose k, or n over k or all k different combinations of n unique items or binomial coefficients in Matlab or in math language

\[\frac{n!}{(n-k)! k!}\]

you can write

nchoosek(n,k)

But lets say you want to generate a list of these possible combinations? Well then you just write n as a vector

n = [1, 2, 3, 4] = [1:4]

so this would generate using $$k = 2$$

nchoosek(1:4,2)[1 21 31 42 32 43 4]

or why not do

nchoosek([1,4,10,17],2) = [1 41 101 174 104 1710 17]

Awesome discovery at 8.00 pm!

Leave a Reply

Your email address will not be published. Required fields are marked *