5.0

5.0 | 3 ratings Rate this file 188 downloads (last 30 days) File Size: 31.63 KB File ID: #24325

COMBINATOR -combinations AND permutations

by Matt Fig

 

02 Jun 2009 (Updated 16 Jun 2009)

Code covered by BSD License  

Returns 1 of 4 different samplings on the set 1:N, taken K at a time.

Download Now | Watch this File

File Information
Description

COMBINATOR will return one of 4 different samplings on the set 1:N, taken K at a time. These samplings are given as follows:
   
PERMUTATIONS WITH REPETITION/REPLACEMENT
  COMBINATOR(N,K,'p','r') -- N >= 1, K >= 0

PERMUTATIONS WITHOUT REPETITION/REPLACEMENT
  COMBINATOR(N,K,'p') -- N >= 1, N >= K >= 0

COMBINATIONS WITH REPETITION/REPLACEMENT
  COMBINATOR(N,K,'c','r') -- N >= 1, K >= 0

COMBINATIONS WITHOUT REPETITION/REPLACEMENT
  COMBINATOR(N,K,'c') -- N >= 1, N >= K >= 0

Example:

combinator(4,2,'p','r') % Permutations with repetition
combinator(4,2,'p') % Permutations without repetition
combinator(4,2,'c','r') % Combinations with repetition
combinator(4,2,'c') % Combinations without repetition
ans =
     1 1
     1 2
     1 3
     1 4
     2 1
     2 2
     2 3
     2 4
     3 1
     3 2
     3 3
     3 4
     4 1
     4 2
     4 3
     4 4
ans =
     1 2
     1 3
     1 4
     2 1
     2 3
     2 4
     3 1
     3 2
     3 4
     4 1
     4 2
     4 3
ans =
     1 1
     1 2
     1 3
     1 4
     2 2
     2 3
     2 4
     3 3
     3 4
     4 4
ans =
     1 2
     1 3
     1 4
     2 3
     2 4
     3 4

The accompanying c++ file can be MEXed to provide the ability to specify N as an int8, int16, or int32. This saves memory and is faster. I have provided a MEX file that was created on Win XP with 2006a that may work. If not, the file will need to be MEXed on your machine.
Please READ the help before using.
I would very much appreciate bug reports sent through email, as well as suggestions for improvement. Thanks.

MATLAB release MATLAB 7.4 (R2007a)
Zip File Content  
Other Files combinator.m,
cumsumall.cpp,
cumsumall.m,
cumsumall.mexw32,
license.txt
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
02 Jun 2009 us

a very nice package/wrapper for a lot of the combinatorial problems almost daily asked for in the NG - or - as the name implies: a TERMINATOR for combiners...

in particular:
- excellent help/good example
- clean engine divided into intelligible subfunctions
- many comments and timings

us

02 Jun 2009 Bruno Luong

Two words: excellent job!

25 Aug 2009 Andrey

Very good.

31 Oct 2009 Michele Costola

If I put a value greater than 170 I get an error.

31 Oct 2009 Matt Fig

Michele,
You didn't give very much information. If you put a number greater than 170 WHERE? And what other parameters? Why don't you just email me? I put my email in the help for that purpose. If you email me, show me EXACTLY what you did, don't be vague.

Please login to add a comment or rating.
Updates
16 Jun 2009

Added ability to specify integer class for N. MEX-File.

Tag Activity for this File
Tag Applied By Date/Time
combinatorics Matt Fig 02 Jun 2009 09:49:19
permutations Matt Fig 02 Jun 2009 09:49:19
combinations Matt Fig 02 Jun 2009 09:49:19
set Matt Fig 02 Jun 2009 09:49:19
perms Matt Fig 02 Jun 2009 09:49:19
nchoosek Matt Fig 02 Jun 2009 09:49:19
multichoose Matt Fig 02 Jun 2009 09:49:19
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com