nchoosek question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

nchoosek question

Frank Palazzolo

Hi,

I am using nchoosek(n,k) to generate the number of combinations
n!/(k!(n-k)!).
Unfortunately, it seems there is no vectorized version, for n and k are
vectors or matrices of the same size.

I don't want to generate the actual combinations, which is what nchoosek()
does if you start using vectors.  Did matlab decided to use the same
function for two different things?  Seems like a bad idea to me. I hate to
iterate through the matrices myself... :(

Thanks,
-Frank



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: nchoosek question

Mike Miller-20
On Fri, 9 Dec 2005, Frank Palazzolo wrote:

> I am using nchoosek(n,k) to generate the number of combinations
> n!/(k!(n-k)!).
> Unfortunately, it seems there is no vectorized version, for n and k are
> vectors or matrices of the same size.


It looks like bincoeff(N,k) does what you want.

bincoeff( reshape( [10:2:20]', 3, 2 ), reshape( [5:10]', 3, 2 ) )

ans =

  252 12870
  924 48620
  3432 184756

Should we do away with nchoosek()?  Alias it to bincoeff()?

Mike



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

RE: nchoosek question

Frank Palazzolo

>It looks like bincoeff(N,k) does what you want.

Thanks - just what I needed!

-Frank




-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------