Build a Relation Between Matrix Elements

조회 수: 1 (최근 30일)
MarshallSc
MarshallSc 2022년 6월 1일
댓글: Voss 2022년 6월 2일
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
MarshallSc
MarshallSc 2022년 6월 1일
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!
MarshallSc
MarshallSc 2022년 6월 1일
I edited the original post with detailed calculation.

댓글을 달려면 로그인하십시오.

채택된 답변

Voss
Voss 2022년 6월 2일
편집: Voss 2022년 6월 2일
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
MarshallSc
MarshallSc 2022년 6월 2일
That was a great observation, you are correct, didn't notice it myself. Thanks a lot!
Voss
Voss 2022년 6월 2일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by