construct a combination matrix from elements of two matrices

6 visualizzazioni (ultimi 30 giorni)
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 Commento
David Goodmanson
David Goodmanson il 3 Dic 2024
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 ?

Accedi per commentare.

Risposte (1)

Sahas
Sahas il 17 Dic 2024
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!

Categorie

Scopri di più su Simulink Environment Customization in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by