Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

nchoosek - Binomial coefficient or all combinations

Syntax

C = nchoosek(n,k)
C = nchoosek(v,k)

Description

C = nchoosek(n,k) where n and k are nonnegative integers, returns n!/((nk)! k!). This is the number of combinations of n things taken k at a time.

C = nchoosek(v,k), where v is a row vector of length n, creates a matrix whose rows consist of all possible combinations of the n elements of v taken k at a time. Matrix C contains n!/((nk)! k!) rows and k columns.

Inputs n, k, and v support classes of float double and float single.

Examples

The command nchoosek(2:2:10,4) returns the even numbers from two to ten, taken four at a time:

     2     4     6     8
     2     4     6    10
     2     4     8    10
     2     6     8    10
     4     6     8    10

Limitations

When C = nchoosek(n,k) has a large coefficient, a warning will be produced indicating possible inexact results. In such cases, the result is only accurate to 15 digits for double-precision inputs, or 8 digits for single-precision inputs.

C = nchoosek(v,k) is only practical for situations where n is less than about 15.

See Also

perms

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS