How to display Numbers of stacking sequence using permutations an combinations. in this case i have 6840 permutations and 1140 combinations. perms(a) command returning error

1 view (last 30 days)
a=[45 45 45 45 45 45 0 0 0 0 0 0 0 0 -45 -45 -45 -45 -45 -45];
% No. of angle =20;
% No. of sub angle =3 Means (45 0 -45)
% 6840 permutations
% 1140 combinations
perms(a);
command is returning error

Accepted Answer

John D'Errico
John D'Errico on 31 Oct 2015
Edited: John D'Errico on 31 Oct 2015
perms is only meaningful when you have distinct elements. When they are not distinct, as you have, the result will be huge, and as you have found, of course it will fail.
However, nothing stops you from writing code that will compute what you wish. You have only 3 distinct elements, so all that matters is knowing how many repetitions of each element there are in the global set.
As far as the claim that there are 6840 permutations of these 20 numbers, that is simply wrong.
You have 20 holes in which to place the number 0. There are 8 zeros to place, so there are
nchoosek(20,8)
ans =
125970
125970 places to put a zero. Of the remaining holes that are unfilled, they must contain either 45 or a -45.
nchoosek(12,6)
ans =
924
There are 924 such arrangements. Therefore, the unique set of permutations of the vector you wish to form will number
nchoosek(20,8)*nchoosek(12,6)
ans =
116396280
So roughly 116 million DISTINCT permutations of those elements.
That array of distinct permutations will require
nchoosek(20,8)*nchoosek(12,6)*20*8
ans =
1.8623e+10
roughly 18 gigabytes of RAM to store, as double precision numbers. If you need something else, and have not described your problem well, then you need to add a comment that explains your problem more clearly. Please do not keep asking the same question though, without bothering to clarify what you want.
  2 Comments
Triveni
Triveni on 31 Oct 2015
I'm very sorry & apologize for bothering you. But lastly please correct this program.
A=[1 1 0 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 0 1];
n2 = numel(A);
b2 = nnz(A);
M2 = 0:ones(1,n2)*pow2(n2-1:-1:0)';
z2 = rem(floor(M2(:)*pow2(1-n2:0)),2);
out = z2(sum(z2,2) == b2,:);
How can i make it for A=[30 30 30 30 30 30 60 60 60 60 60 60 60 60 30 30 30 30 30 30]???
for 0 and 1 it's work perfectly
i don't have to display these values. i just want to know size and store layup or call any layup. I have to call A(i) alternately for optimized value. or it permute up to maximum allowable range or up to 1 million or more permutations......please help me.
John D'Errico
John D'Errico on 1 Nov 2015
If you have only two unique elements in the vector A, it is simple. Just solve the problem as you did for A above, only using Ahat.
Aelem = unique(A);
Ahat = (A == Aelem(1));
Then use indexing to convert it to
out = Aelem(out+1);
If you have more than 2 distinct elements, then you will end up with MANY distinct permutations, as I showed in my answer, and vectors of this length will generally have no solution using a reasonable amount of RAM.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 30 Oct 2015
When you want the number of them, you should be using nchoosek(). perms() is for listing permutations.

Community Treasure Hunt

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

Start Hunting!