octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with nchoosek


From: Michael Godfrey
Subject: Re: Help with nchoosek
Date: Sun, 31 Aug 2014 10:32:41 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0


Error using nchoosek (line 48)
K must be an integer between 0 and N.

>> nchoosek ([4 5], 8)

ans =

   Empty matrix: 0-by-8
-----------------------------------------------------------------

I find this behaviour of Matlab rather unfortunate. Actually, I would have defined the output to be 0 and [0 0].

Having nchoosek (n, k) be 0 when k > n is a very useful convention that make lots of combinatorial formulas easier to write (and prove).

This is for instance the behaviour of R:

-----------------------------------------------------------------
> choose (5, 8)
[1] 0
> choose (c(4, 5), 8)
[1] 0 0
-----------------------------------------------------------------

and Python + SciPy:

-----------------------------------------------------------------
>>> from scipy.special import binom
>>> binom(5, 8)
0.0
>>> binom((4, 5), 8)
array([ 0.,  0.])
-----------------------------------------------------------------

@++
Julien


This is a good case for compatibility with R.  And, it would ba appropriate
to document that the incompatibility with Matlab is intentional.

Michael




reply via email to

[Prev in Thread] Current Thread [Next in Thread]