Mercurial > hg > octave-lyh
changeset 6318:bae85c1e0e2a
[project @ 2007-02-16 08:15:25 by jwe]
author | jwe |
---|---|
date | Fri, 16 Feb 2007 08:15:25 +0000 |
parents | 8c67f8be341d |
children | e7e7c338bf99 |
files | scripts/specfun/nchoosek.m |
diffstat | 1 files changed, 16 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/specfun/nchoosek.m +++ b/scripts/specfun/nchoosek.m @@ -61,22 +61,23 @@ function A = nchoosek (v, k) if (nargin == 2) - n = length (v); - if (n == 1) - A = round (exp (sum (log (k+1:v)) - sum (log (2:v-k)))); - elseif (k == 0) - A = []; - elseif (k == 1) - A = v(:); - elseif (k == n) - A = v(:).'; - else - m = round (exp (sum (log (k:n-1)) - sum (log (2:n-k)))); - A = [v(1)*ones(m,1), nchoosek(v(2:n),k-1); - nchoosek(v(2:n),k)]; - endif - else print_usage (); endif + n = length (v); + + if (n == 1) + A = round (exp (sum (log (k+1:v)) - sum (log (2:v-k)))); + elseif (k == 0) + A = []; + elseif (k == 1) + A = v(:); + elseif (k == n) + A = v(:).'; + else + m = round (exp (sum (log (k:n-1)) - sum (log (2:n-k)))); + A = [v(1)*ones(m,1), nchoosek(v(2:n),k-1); + nchoosek(v(2:n),k)]; + endif + endfunction