Could anyone help me how to execute array of larger size.
Mostrar comentarios más antiguos
I want to execute the following line
A=partitions(100)
When i execute the code I am getting the following error
Error using cell
Maximum variable size allowed by the program is exceeded.
Error in partitions (line 64)
C = cell(S,1); % Main Cell.
Error in test (line 1)
A=partitions(100)
In the same line when i used
A=partitions(10)
It executes.
Could anyone help me is there any other way to execute it for 100.
6 comentarios
Walter Roberson
el 8 de Nov. de 2021
partions(100) would contain 190569292 entries of varying length, up to length 100.
Are you using John D'Errico's https://www.mathworks.com/matlabcentral/fileexchange/12009-partitions-of-an-integer ?
Walter Roberson
el 8 de Nov. de 2021
There are two different partition functions that might be of interest.
In one of them, Wolfram refers to as PartitionP https://mathworld.wolfram.com/PartitionFunctionP.html counts the number of integer partitions of a number, where order does not matter, so 1 + 2 + 3 is considered the same as 2 + 3 + 1 but different than 1 + 1 + 2 + 2. When this is what is desired, then for input of 100, the output would have 190569292 entries.
The other meaning is the number of ways to partition the input into non-empty subsets; Wolfram counts those with the Bell Number function https://mathworld.wolfram.com/BellNumber.html . For 100, this is about 47.5 * 10^114 . This is what Matt's function tries to output. If that is what you are trying to build, then there is no realistic way you could build the entire list, and your system would probably give out around (15) or (16)
Which of these are you after? If you are looking for partitions of integers, then it might be practical to generate them all for 100 (but it might take work to get through the last few of them.)
What are you planning to do with the output ?
Stephen23
el 9 de Nov. de 2021
jaah navi's incorrectly posted "Answers" moved here (copyright code removed and replaced with hyperlink):
I am not using John D'Errico's https://www.mathworks.com/matlabcentral/fileexchange/12009-partitions-of-an-integer
I am using the partitions function as provided in the attachment. EDIT: https://www.mathworks.com/matlabcentral/fileexchange/24185-partitions
With respect to your comment I am with the number of ways to partition the input into non-empty subsets using Bell Number function https://mathworld.wolfram.com/BellNumber.html .
As you have mentined there is no realistic way to build the entire list for 100 could you please help me with other way to solve it.
Walter Roberson
el 9 de Nov. de 2021
What are you going to do with the list of subsets if you were able to generate them?
Imagine if I were to provide a URL that you could invoke, passing in a 107 digit decimal subset number, and the site returned back the next 2^30 = 1073741824 subsets. I estimate that each subset should require between 2 bytes and 80 or so bytes, so if we guess that each subset will average 50 bytes, that would be about 50 gigabytes per subset, perhaps as much as 100 Gigabyte. And there would be 36695977855841144185773134324833391052745039826692497979801421430190766017415756929120296849762010984873984 such subsets.
But suppose you have a fast network connection and were able to download one of the subsets in 30 minutes (my home network connection just might be able to handle that, maybe), so half an hour later you have the first giga-entries and it might plausibly fit within your computer memory (in reality probably a smaller subset would be needed at a time.) But suppose I could provide such a service. Or suppose I were able to provide a Dropbox or Google Drive site that could provide the first 4 billion or so entries in chunks that take about 8 gigabytes to store. If I could provide those to you, what would you do with the data ?
jaah navi
el 10 de Nov. de 2021
Imagine you have a 64 core machine, with each of the cores operating at 5 gigahertz clock rate. Imagine further that you could fully evaluate based on one of the subsets in 1 clock instruction (which is obviously not enough for real work, but perhaps would be enough for the simple task of counting the state.) Under this imaginary scenario, you could count
format long g
max_per_second = 5*10^9 * 64
bell100 = bell_number(100)
seconds_required = seconds(double(bell100) / max_per_second)
years(seconds_required)
That is over 10^96 years -- 4.7 yotta yotta yotta yotta years.
To put it another way, if you had started at the time the universe formed,
universe_age_seconds = str2sym('436117076900000000')
operations_per_second_needed = vpa(bell100 / universe_age_seconds)
If the universe is in the upper limit of how large it is estimated to be, and if every elementary particle in the universe had been calculating at about 10^12 operations per second since the time the universe began just to count the subsets, then it would be about ready now.
When I say "upper limit", I mean that the generally accepted size is about a factor of 10^10 smaller, but a few people have speculated that if one of the modified gravity theory holds, and there are extensions to the Standard Model, that there might be a lot more to the Universe than has been calculated.
All of which is to say that the probability that you would be able to successfully do an exhaustive search over the desired domain is ZERO.
function B = bell_number(nfinal)
if nfinal == 100
B = str2sym('47585391276764833658790768841387207826363669686825611466616334637559114497892442622672724044217756306953557882560751');
return
end
b = zeros(1, nfinal+1, 'sym');
b(1) = 1;
for i = 2:nfinal+1
b(i) = sym(0);
for j = 0:i-2
b(i) = b(i)+nchoosek(sym(i-2),sym(j))*b(j+1);
end
end
B = b(end);
end
Respuestas (0)
Categorías
Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!