Integer partition generator

버전 1.11.0.0 (5.44 KB) 작성자: David Holdaway
Generates a table of all integer partitions of integers from 0 to N.
다운로드 수: 1.1K
업데이트 날짜: 2012/6/11

라이선스 보기

Integer partitions are the different ways to express an integer say "4" as a sum of other positive integers, in this case we would have 4=4,3+1,2+2,2+1+1,1+1+1+1. This program calculates all the partitions of every integer up to N which it stores in a cell array.

There is the option of only using partitions with up to "maxnum" integers, e.g. if maxnum = 3 the parition 1+1+1+1 (of 4) would be disallowed.

Also contained is a file to generate the number of integer partitions of an integer N using up to k integers which is used in the main file. Both files work via the recursive property of integer partitions and use integer class variables.

Update: Version two also allows the extra option of using only a restricted range of integers for the partition as well as a restricted number.

Example Useage:

Say I wanted to generate all the partitions of the numbers 0-100, using at most 6 numbers. Of which there are 3574454 this is calculated by:
table = integerparttable(100);
>> sum(table(:,7))

This set would be given by:
parts = intpartgen(100,6);
(Which takes ~ 20 seconds to compute on my machine.)

If I later wanted to extend this set to all the partitions up to 110, I can pass this list back to the function so it doesn't have to recalculate them all

parts = intpartgen(110,6,parts);

Note that parts{k+1} is the partitions of k (since arrays start from 1 and the partition for 0 is included as part{1})

To calculate the number of ways to pay a sum of money at most 10 coins
>>> intlist = intpartgen2(value,10,[],[0,1,2,5,10,20,50,100]);
>>> ways_to_pay = intlist{value+1};
(for exactly 10 coins remove the value zero from allowed numbers)

인용 양식

David Holdaway (2024). Integer partition generator (https://www.mathworks.com/matlabcentral/fileexchange/36437-integer-partition-generator), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2012a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.11.0.0

previously uploaded the wrong file!

1.10.0.0

Corrected help comments

1.9.0.0

Edited comment blocks to be continuous and show up when command "help" is used

1.8.0.0

Edited comment list to be one continuous block and thus show up when "help" is used

1.4.0.0

Version two allows the extra option of using only a restricted range of integers for the partition as well as a restricted number.

1.2.0.0

Updated Description to give example usage

1.1.0.0

Updated help, added feature to allow a cut off in partition length.

1.0.0.0