Documentation Center

  • Trial Software
  • Product Updates

nchoosek

Binomial coefficient

Syntax

nchoosek(n,k)

Description

nchoosek(n,k) returns the binomial coefficient of n and k.

Input Arguments

n

Symbolic number, variable or expression.

k

Symbolic number, variable or expression.

Examples

Compute the binomial coefficients for these expressions:

syms n
[nchoosek(n, n), nchoosek(n, n + 1), nchoosek(n, n - 1)]
ans =
[ 1, 0, n]

If one or both parameters are negative numbers, convert these numbers to symbolic objects:

[nchoosek(sym(-1), 3), nchoosek(sym(-7), 2), nchoosek(sym(-5), -5)]
ans =
[ -1, 28, 1]

If one or both parameters are complex numbers, convert these numbers to symbolic objects:

[nchoosek(sym(i), 3), nchoosek(sym(i), i), nchoosek(sym(i), i + 1)]
ans =
[ 1/2 + i/6, 1, 0]
 

Differentiate the binomial coefficient:

syms n
diff(nchoosek(n, 2))
ans =
-(psi(n - 1) - psi(n + 1))*nchoosek(n, 2)
 

Expand the binomial coefficient:

syms n k
expand(nchoosek(n, k))
ans =
-(n*gamma(n))/(k^2*gamma(k)*gamma(n - k) - k*n*gamma(k)*gamma(n - k))

More About

expand all

Binomial Coefficient

If n and k are integers and 0 ≤ k ≤ n, the binomial coefficient is defined as:

For complex numbers, the binomial coefficient is defined via the gamma function:

Tips

  • Calling nchoosek for numbers that are not symbolic objects invokes the MATLAB® nchoosek function.

  • If one or both parameters are complex or negative numbers, convert these numbers to symbolic objects using sym, and then call nchoosek for those symbolic objects.

Algorithms

If k < 0 or n – k < 0, nchoosek(n,k) returns 0.

If one or both arguments are complex, nchoosek uses the formula representing the binomial coefficient via the gamma function.

See Also

| | | | |

Was this topic helpful?