construct a combination matrix from elements of two matrices
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
David Goodmanson
le 3 Déc 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 ?
Réponses (1)
Sahas
le 17 Déc 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!
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!