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)
Show older comments
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
2 Comments
John D'Errico
on 31 Oct 2015
Please edit your question to give a better idea of what you need. Do not just keep adding new questions on the same topic.
Accepted Answer
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
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.
More Answers (1)
Walter Roberson
on 30 Oct 2015
When you want the number of them, you should be using nchoosek(). perms() is for listing permutations.
2 Comments
Walter Roberson
on 31 Oct 2015
Your question asked about displaying the number of items. perms() never tells you the number,it is only for listing all of the permutations.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!