[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help with nchoosek
From: |
Julien Bect |
Subject: |
Re: Help with nchoosek |
Date: |
Sun, 31 Aug 2014 09:10:51 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.0 |
Le 31/08/2014 05:43, Rik a écrit :
nchoosek ([4 5], 8)
With Matlab R2012a:
-----------------------------------------------------------------
>> nchoosek (5, 8)
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