Binomial coefficient

From Wikimization

(Difference between revisions)
Jump to: navigation, search
(Matlab nchoosek is incomplete for negative arguments.)
(binomial coefficient, full definition, Matlab)
Line 1: Line 1:
-
== binomial coefficient, full definition, Matlab ==
+
== full definition, Matlab ==
binomial coefficient from M.J. Kronenburg
binomial coefficient from M.J. Kronenburg
[https://arxiv.org/pdf/1105.3689.pdf]
[https://arxiv.org/pdf/1105.3689.pdf]

Revision as of 18:18, 27 January 2022

full definition, Matlab

binomial coefficient from M.J. Kronenburg [1]

Also see: Wolfram LaTeX: \alpha

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
Personal tools