# Binomial coefficient

(Difference between revisions)
 Revision as of 18:18, 27 January 2022 (edit) (→binomial coefficient, full definition, Matlab)← Previous diff Current revision (20:08, 4 March 2022) (edit) (undo) Line 4: Line 4: Also see: [https://www.wolframalpha.com/input/?i=binomial+coefficient&assumption=%7B%22F%22%2C+%22BinomialCoefficientCalculator%22%2C+%22n%22%7D+-%3E%22-10%22&assumption=%7B%22F%22%2C+%22BinomialCoefficientCalculator%22%2C+%22k%22%7D+-%3E%225%22&assumption=%7B%22C%22%2C+%22binomial+coefficient%22%7D+-%3E+%7B%22Calculator%22%7D Wolfram $\alpha$] Also see: [https://www.wolframalpha.com/input/?i=binomial+coefficient&assumption=%7B%22F%22%2C+%22BinomialCoefficientCalculator%22%2C+%22n%22%7D+-%3E%22-10%22&assumption=%7B%22F%22%2C+%22BinomialCoefficientCalculator%22%2C+%22k%22%7D+-%3E%225%22&assumption=%7B%22C%22%2C+%22binomial+coefficient%22%7D+-%3E+%7B%22Calculator%22%7D Wolfram $\alpha$] + + [[Image:Binomial.jpg|thumb|right|700px|full binomial coefficient definition including negative argument]]

## full definition, Matlab

binomial coefficient from M.J. Kronenburg [1]

full binomial coefficient definition including negative argument
function y = binomial(n, k)
if ~k || k == n
y = 1;
elseif k == 1
y = n;
elseif n < 0
if k > 0
y = (-1)^k*nchoosek(-n+k-1, k);
elseif k <= n
y = (-1)^(n-k)*nchoosek(-k-1, n-k);
elseif n < k && k < 0
y = 0;
end
elseif n >= 0
if k < 0 || k > n
y = 0;
else
y = nchoosek(n,k);
end
end
return