Akzeptierte Antwort

Stephen23
Stephen23 am 4 Aug. 2021

1 Stimme

n = 5;
r = 2:5;
F = @(k)any(permute(nchoosek(1:n,k),[3,1,2])==(1:n).',3);
M = cell2mat(arrayfun(F,r,'uni',0))
M = 5×26 logical array
1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 0 1 1 0 1 0 0 1 0 0 1 1 0 1 0 0 1 1 0 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 1 1 0 1 1 1 1 0 0 0 1 0 0 1 0 1 1 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 1

4 Kommentare

Sourasis Chattopadhyay
Sourasis Chattopadhyay am 18 Aug. 2021
When I am running this code for n = 50 or 100 (n>25) In this case I am gettiing this type of error . What should I do?
For n = 100, you want a 100 x (100C7)) matrix, at least. That would require
space = 100 * nchoosek(sym(100),sym(7))
space = 
1600756080000
Gb = vpa(space/2^30,6)
Gb = 
1490.82
close to 1.5 terabytes, at least, even in the best case situation (no intermediate arrays of notable size.)
If your system cannot handle 32 gigabytes, what is your plan to handle 45 times as much memory (at minimum, if no duplicate copies have to be made for temporary computations) ?
Sourasis Chattopadhyay
Sourasis Chattopadhyay am 19 Aug. 2021
Thank you for you answer .
You might be able to fit the 50 case. Change to
F = @(k)any(permute(nchoosek(uint8(1:n),k),[3,1,2])==uint8(1:n).',3);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by