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
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
John D'Errico
2015-10-31
Please edit your question to give a better idea of what you need. Do not just keep adding new questions on the same topic.
采纳的回答
John D'Errico
2015-10-31
编辑:John D'Errico
2015-10-31
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 个评论
John D'Errico
2015-11-1
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.
更多回答(1 个)
Walter Roberson
2015-10-30
When you want the number of them, you should be using nchoosek(). perms() is for listing permutations.
2 个评论
Walter Roberson
2015-10-31
Your question asked about displaying the number of items. perms() never tells you the number,it is only for listing all of the permutations.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!