Find unique permutations of a matrix
14 ビュー (過去 30 日間)
古いコメントを表示
I want to construct all possible matrices with N elements. Example: if N=6, then I want a 1x6, 2x3 3x2 and 6x1 matrix. These matrices should all be unique. So if we consider a 2x3 matrix, the options would be: [1 2 3; 4 5 6], [1 2 4; 3 5 6], [1 2 5; 3 4 6], [1 2 6; 3 4 5], [1 3 4; 2 5 6], [1 3 5; 2 4 6], etc. For this matrix there will be 10 unique combinations. A similar expression for a 3x2 matrix can be obtained: [1 2; 3 4; 5 6], [1 2; 3 5; 4 6], [1 2; 3 6; 4 5], [1 3; 2 4; 5 6], etc. For this matrix there will be 15 unique combinations. The 1x6 and 6x1 matrices only contain 1 unique combination each. Note that the order of rows and the order within each row does not matter and each number can only be used once! So far, I did this manually for N=1:7. For a larger number of N, the number of combinations will explode. For N=12, there will be 32034 combinations possible...
I already did several attempts to obtain all possible matrices and searched for people who tackled similar problems . However, these options do not give the desired results. Can someone please help me? Thank you in advance!
1 件のコメント
Bruno Luong
2018 年 11 月 22 日
編集済み: Bruno Luong
2018 年 11 月 22 日
"For a larger number of N, the number of combinations will explode. For N=12, there will be 32034 combinations possible..."
At least you realize you are engaging in the bad way solving of whatever the problem you want to solve.
I count 2874009600 combinations possible.
回答 (1 件)
Bruno Luong
2018 年 11 月 22 日
N = 6;
p = factor(N);
q = length(p);
b = dec2bin(0:2^q-1,q)-'0';
m = unique(prod(b.*p+(1-b),2));
n = N./m;
C = num2cell(perms(1:N),2);
reshapefun = @(m,n) cellfun(@(A) reshape(A,[m n]), C, 'unif', 0);
C = arrayfun(@(m,n) reshapefun(m,n), m, n, 'unif', 0);
C = cat(1,C{:})
5 件のコメント
Bruno Luong
2018 年 11 月 22 日
編集済み: Bruno Luong
2018 年 11 月 22 日
How voltage/current criteria translates to the array values? sum(a,2) is the same? Or something more complicated such as Kirshoff's circuit law?
There are other numerical technique to optimize the arrangement on whatever criteria you want to optimize. IMHO going bruteforce is not a wise way to go.
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!