Build a Relation Between Matrix Elements

I have a complex valued matrix for example:
a = complex(1.1,-1.3); b = complex(1.3,1.2);c = complex(1.5,-1.4); d = complex(1.8,1.2); % random numbers
A = [a b; c d];
How can I build a relation between the elements of the matrix as, and then get the sume for each element. All the relations would be calculated as:
A1_1 = A(1) + A(2) + A(3) + A(4);
A1_2 = A(1) + A(2) + A(3) - A(4);
A1_3 = A(1) + A(2) - A(3) + A(4);
A1_4 = A(1) - A(2) + A(3) - A(4);
A1_5 = A(1) + A(2) - A(3) - A(4);
A1_6 = A(1) - A(2) - A(3) + A(4);
A1_7 = A(1) - A(2) + A(3) + A(4);
A1_8 = A(1) - A(2) - A(3) - A(4);
A2_1 = A(2) + A(3) + A(4) + A(1);
A2_2 = A(2) + A(3) + A(4) - A(1);
A2_3 = A(2) + A(3) - A(4) + A(1);
A2_4 = A(2) - A(3) + A(4) - A(1);
A2_5 = A(2) + A(3) - A(4) - A(1);
A2_6 = A(2) - A(3) - A(4) + A(1);
A2_7 = A(2) - A(3) + A(4) + A(1);
A2_8 = A(2) - A(3) - A(4) - A(1);
A3_1 = A(3) + A(4) + A(1) + A(2);
A3_2 = A(3) + A(4) + A(1) - A(2);
A3_3 = A(3) + A(4) - A(1) + A(2);
A3_4 = A(3) - A(4) + A(1) - A(2);
A3_5 = A(3) + A(4) - A(1) - A(2);
A3_6 = A(3) - A(4) - A(1) + A(2);
A3_7 = A(3) - A(4) + A(1) + A(2);
A3_8 = A(3) - A(4) - A(1) - A(2);
A4_1 = A(4) + A(3) + A(2) + A(1);
A4_2 = A(4) + A(3) + A(2) - A(1);
A4_3 = A(4) + A(3) - A(2) + A(1);
A4_4 = A(4) - A(3) + A(2) - A(1);
A4_5 = A(4) + A(3) - A(2) - A(1);
A4_6 = A(4) - A(3) - A(2) + A(1);
A4_7 = A(4) - A(3) + A(2) + A(1);
A4_8 = A(4) - A(3) - A(2) - A(1);
A1 = A1_1 + A1_2 + A1_3 + A1_4 + A1_5 + A1_6 + A1_7 + A1_8
A1 = 8.8000 - 10.4000i
A2 = A2_1 + A2_2 + A2_3 + A2_4 + A2_5 + A2_6 + A2_7 + A2_8
A2 = 12.0000 - 11.2000i
A3 = A3_1 + A3_2 + A3_3 + A3_4 + A3_5 + A3_6 + A3_7 + A3_8
A3 = 10.4000 + 9.6000i
A4 = A4_1 + A4_2 + A4_3 + A4_4 + A4_5 + A4_6 + A4_7 + A4_8
A4 = 14.4000 + 9.6000i
ANew = [A1 A2; A3 A4]
ANew =
8.8000 -10.4000i 12.0000 -11.2000i 10.4000 + 9.6000i 14.4000 + 9.6000i

4 Comments

I'm sorry, but this makes no sense as you said it. Are you asking to generate some sort of "random" matrix with some property as a relationship between the elements? Or, are you asking to compute the set of combinations of all elements of some given matrix? If it is the latter, then it would be easy, even trivial, as long as the matrix is not too large. If the former in some form, then you need to explain yourself far more clearly. In any case, you should be explicit.
I'm asking to compute the combinations between all elements of the matrix. Yeah It's a little bit untangible so let me explain clearly. The matrix that I'm performing the calcualtion on is (3,3,16,729) that is complex. For simplicity let's assume a 2 x 2 matrix as:
a = complex(1.1,-1.3); b = complex(1.3,1.2);c = complex(1.5,-1.4); d = complex(1.8,1.2); % random numbers
A = [a b; c d]
A =
1.1000 - 1.3000i 1.3000 + 1.2000i 1.5000 - 1.4000i 1.8000 + 1.2000i
Now, I want to build a relation between the elements of the matrix (for the original matrix, I have to do this procedure for each small matrix). Let's calculate all of them for a 2 x 2 matrix :
A1 = A(1) + A(2) + A(3) + A(4)
A1 = 5.7000 - 0.3000i
A2 = A(1) + A(2) + A(3) - A(4)
A2 = 2.1000 - 2.7000i
A3 = A(1) + A(2) - A(3) + A(4)
A3 = 3.1000 - 2.7000i
A4 = A(1) - A(2) + A(3) - A(4)
A4 = -0.9000 + 0.1000i
A5 = A(1) + A(2) - A(3) - A(4)
A5 = -0.5000 - 5.1000i
A6 = A(1) - A(2) - A(3) + A(4)
A6 = 0.1000 + 0.1000i
A7 = A(1) - A(2) + A(3) + A(4)
A7 = 2.7000 + 2.5000i
A8 = A(1) - A(2) - A(3) - A(4)
A8 = -3.5000 - 2.3000i
These are the 8 relations ( 2 ^ numel - 1) of 2 x 2 matrix. This concept is part of a deep learning algorithm that I'm trying to develop. I'm basically looking to write a function that can do this computation for any matrices. I hope that explains better.
Sorry, I forgot to mention that this procedure is done for each element and the sum is considered. For example, for the first and second element it would be:
a = complex(1.1,-1.3); b = complex(1.3,1.2);c = complex(1.5,-1.4); d = complex(1.8,1.2); % random numbers
A = [a b; c d]
A =
1.1000 - 1.3000i 1.3000 + 1.2000i 1.5000 - 1.4000i 1.8000 + 1.2000i
A1_1 = A(1) + A(2) + A(3) + A(4);
A1_2 = A(1) + A(2) + A(3) - A(4);
A1_3 = A(1) + A(2) - A(3) + A(4);
A1_4 = A(1) - A(2) + A(3) - A(4);
A1_5 = A(1) + A(2) - A(3) - A(4);
A1_6 = A(1) - A(2) - A(3) + A(4);
A1_7 = A(1) - A(2) + A(3) + A(4);
A1_8 = A(1) - A(2) - A(3) - A(4);
A2_1 = A(2) + A(3) + A(4) + A(1);
A2_2 = A(2) + A(3) + A(4) - A(1);
A2_3 = A(2) + A(3) - A(4) + A(1);
A2_4 = A(2) - A(3) + A(4) - A(1);
A2_5 = A(2) + A(3) - A(4) - A(1);
A2_6 = A(2) - A(3) - A(4) + A(1);
A2_7 = A(2) - A(3) + A(4) + A(1);
A2_8 = A(2) - A(3) - A(4) - A(1);
% and for A(3) and A(4) too
A1 = A1_1 + A1_2 + A1_3 + A1_4 + A1_5 + A1_6 + A1_7 +A1_8
A1 = 8.8000 - 10.4000i
A2 = A2_1 + A2_2 + A2_3 + A2_4 + A2_5 + A2_6 + A2_7 +A2_8
A2 = 12.0000 - 11.2000i
Notice that the sign of the first element stays the same (positve). Thank you!
I edited the original post with detailed calculation.

Sign in to comment.

 Accepted Answer

Voss
Voss on 2 Jun 2022
Edited: Voss on 2 Jun 2022
If that's really what you want to do, notice that if you sum these 8 equations:
A1_1 = A(1) + A(2) + A(3) + A(4);
A1_2 = A(1) + A(2) + A(3) - A(4);
A1_3 = A(1) + A(2) - A(3) + A(4);
A1_4 = A(1) - A(2) + A(3) - A(4);
A1_5 = A(1) + A(2) - A(3) - A(4);
A1_6 = A(1) - A(2) - A(3) + A(4);
A1_7 = A(1) - A(2) + A(3) + A(4);
A1_8 = A(1) - A(2) - A(3) - A(4);
You get A1_1+A1_2+...+A1_8 = 8*A(1)
That's because all the A(2), A(3), and A(4) terms on the right-hand side add to zero. That is, there are 4 positive copies and 4 negative copies of each of A(2), A(3), A(4), so their sum is 0.
Therefore, the end result you're after is:
ANew = 8*A
(I think you have it transposed in the question, i.e., it should be ANew = [A1 A3; A2 A4]; that is, A2 comes from A(2), which is c, not b.)

2 Comments

That was a great observation, you are correct, didn't notice it myself. Thanks a lot!
You're welcome!

Sign in to comment.

More Answers (0)

Tags

Asked:

on 1 Jun 2022

Commented:

on 2 Jun 2022

Community Treasure Hunt

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

Start Hunting!