nchoosekFS

nchoosekFS returns the Binomial coefficient or matrix containing all combinations

Syntax

Description

example

c =nchoosekFS(v, k) Binomial coefficient(s) or all combinations.

Examples

expand all

  • Binomial coefficient(s) or all combinations.
  • Profile generation of 2118760 combinations.

    v = 1:50; k = 4; 
    tic
    for i=1:10, nchoosekFS(v,k); end
    t_nchoosekFS = toc
    tic
    for i=1:10, nchoosek(v,k); end
    t_nchoosek = toc
    fprintf('nchoosekFS has been %5.2f times faster than nchoosek\n\n\n', t_nchoosek/t_nchoosekFS); 
    fprintf('Try now again using k=5: in a 32 bit computer\n');
    fprintf('nchoosekFS will require about the same time (in order of magnitude)\n');
    fprintf('while nchoosek will start swaping into virtual memory.\n');
    t_nchoosekFS =
    
        0.0199
    
    
    t_nchoosek =
    
        0.0690
    
    nchoosekFS has been  3.46 times faster than nchoosek
    
    
    Try now again using k=5: in a 32 bit computer
    nchoosekFS will require about the same time (in order of magnitude)
    while nchoosek will start swaping into virtual memory.
    

    Input Arguments

    expand all

    v — Vector of length n. Integer or array of non-negative integers.

    Data Types: single|double

    k — Items to choose from the set of n elements. Non negative integer.

    Data Types: single|double

    More About

    expand all

    Additional Details

    This function is similar to nchoosek of Statistics Toolbox but it is much faster and makes a more efficient use of memory.

    Returns the scalar $v!/k!(v-k)!$ if $v$ and $k$ are non-negative integers.

    This is the number of combinations of $v$ things taken $k$ at a time. In this case it makes use of function bc.

    Produces a matrix with $n!/k!(n-k)!$ rows and $k$ columns if $v$ is a vector of length $n. Each row contains a combination of k elements taken without repetitions among n. In this case function combsFS is used.

    References

    Riordan, J. (1958), "An Introduction to Combinatorial Analysis", Wiley & Sons, New York.

    See Also

    |

    This page has been automatically generated by our routine publishFS