How to calculate the total number of incidences of a kj part in all compositions of a natural number N
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
A composition of natural number N is a partition in ki summands(parts) of N=k1+k2+k3+k4...+ki , with ki >or =1 and ki<N, where the order of the parts is important. For instance there are 3 compositions of N=3 are: {1,1,1} {1,2} {2,1}
2 Kommentare
Antworten (1)
Kaitlyn Keil
am 27 Jul. 2018
Here is a loop that will print this out for you, though it does include the single case (just the number itself):
function count = countAllCombinators(arr, n)
if n==0
disp(arr);
count = 1;
elseif(n > 0)
count = 0;
for k = 1:n
subarr = [arr k];
count = count + countAllCombinators(subarr, n-k);
end
end
end
Hope that helps!
Siehe auch
Kategorien
Mehr zu Elementary Math finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!