construct a combination matrix from elements of two matrices

5 ビュー (過去 30 日間)
LH
LH 2024 年 12 月 3 日
回答済み: Sahas 2024 年 12 月 17 日
Hi all,
I have two matricesAand B, as shown below. Each element is then extended into two which doubles each row, i.e., this gives extended matrices. What I need to get is the combination between all of these extended elements (for each original row) as shown on the right of the figure where, for example, means the multiplication of all these elements. As a result, each combination matrix should be containing all possible combinations, but I am struggling to know how to get it.
Any help would be appreicted.
Thanks.
  1 件のコメント
David Goodmanson
David Goodmanson 2024 年 12 月 3 日
Hi LH, looking at the 'all possible combinations' in the upper right box above, and ignoring the subscripts which are always 1, and ignoring the primed a's and b's for the moment, you have three combinations:
a1b1, a1b2, a2b1, where these are superscripts. Is there a reason not to have a2b2 ?

サインインしてコメントする。

回答 (1 件)

Sahas
Sahas 2024 年 12 月 17 日
Hi,
I can't identify any pattern or rule to systematically generate the resulting two matrices using a "for" loop. Therefore, I've provided the following hardcoded implementation. You can edit and replace the positions of the elements if needed.
A = [a1, b1; a2, b2];
B = [a1_hat, b1_hat; a2_hat, b2_hat];
A_ext = [A(1,1), A(1,2); A(1,1), A(1,2); A(2,1), A(2,2); A(2,1), A(2,2)];
B_ext = [B(1,1), B(1,2); B(1,1), B(1,2); B(2,1), B(2,2); B(2,1), B(2,2)];
C1 = [
A_ext(1,1)*B_ext(1,1)*A_ext(1,1)*B_ext(1,1), A_ext(1,1)*B_ext(2,1)*A_ext(1,1)*B_ext(1,1), A_ext(2,1)*B_ext(1,1)*A_ext(1,1)*B_ext(1,1);
A_ext(1,1)*B_ext(1,1)*A_ext(1,1)*B_ext(2,2), A_ext(1,1)*B_ext(2,1)*A_ext(1,1)*B_ext(2,2), A_ext(2,1)*B_ext(1,1)*A_ext(1,1)*B_ext(2,2);
A_ext(1,1)*B_ext(1,1)*A_ext(2,1)*B_ext(1,1), A_ext(1,1)*B_ext(2,1)*A_ext(2,1)*B_ext(1,1), A_ext(2,1)*B_ext(1,1)*A_ext(2,1)*B_ext(1,1)
];
C2 = [
A_ext(3,1)*B_ext(3,1)*A_ext(1,1)*B_ext(1,1), A_ext(3,1)*B_ext(4,1)*A_ext(1,1)*B_ext(1,1), A_ext(4,1)*B_ext(3,1)*A_ext(1,1)*B_ext(1,1);
A_ext(3,1)*B_ext(3,1)*A_ext(1,1)*B_ext(2,2), A_ext(3,1)*B_ext(4,1)*A_ext(1,1)*B_ext(2,2), A_ext(4,1)*B_ext(3,1)*A_ext(1,1)*B_ext(2,2);
A_ext(3,1)*B_ext(3,1)*A_ext(2,1)*B_ext(1,1), A_ext(3,1)*B_ext(4,1)*A_ext(2,1)*B_ext(1,1), A_ext(4,1)*B_ext(3,1)*A_ext(2,1)*B_ext(1,1)
];
I hope this is beneficial!

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by