3

I am a complete beginner in Mathematica and I have a small problem.

enter image description here

I have this three matrices (A,B and C) and with them I have to build larger matrix M which looks like this.

enter image description here

What would be the easiest way to do this Mathematica?

So far I have this:

A = Table[Subscript[a, i, j], {i, 6}, {j, 6}];
B = Table[Subscript[b, i, j], {i, 6}, {j, 6}];
C = Table[Subscript[c, i, j], {i, 6}, {j, 6}];
Ferha7
  • 33
  • 2

2 Answers2

5

I think that this kind of step-by-step assignment is probably the easiest for you to follow and apply generally at this time:

aa = Table[Subscript[a, i, j], {i, 6}, {j, 6}];
bb = Table[Subscript[b, i, j], {i, 6}, {j, 6}];
cc = Table[Subscript[c, i, j], {i, 6}, {j, 6}];

new = ConstantArray[0, {12, 12}];

new[[1 ;; 3, 1 ;; 6]] = aa[[1 ;; 3]];
new[[1 ;; 3, 1 ;; 3]] += cc[[1 ;; 3, 1 ;; 3]];
new[[1 ;; 3, 4 ;; 6]] += bb[[1 ;; 3, 4 ;; 6]];
new[[4 ;; 6, 4 ;; 6]] = cc[[4 ;; 6, 4 ;; 6]];
new[[7 ;; 9, 1 ;; 3]] = aa[[4 ;; 6, 4 ;; 6]] + bb[[1 ;; 3, 1 ;; 3]];
new[[7 ;; 9, 4 ;; 6]] = bb[[1 ;; 3, 1 ;; 3]] + cc[[1 ;; 3, 1 ;; 3]];
new[[10 ;; 12, 10 ;; 12]] = aa[[4 ;; 6, 1 ;; 3]];

new // MatrixForm

$\left( \begin{array}{cccccccccccc} a_{1,1}+c_{1,1} & a_{1,2}+c_{1,2} & a_{1,3}+c_{1,3} & a_{1,4}+b_{1,4} & a_{1,5}+b_{1,5} & a_{1,6}+b_{1,6} & 0 & 0 & 0 & 0 & 0 & 0 \\ a_{2,1}+c_{2,1} & a_{2,2}+c_{2,2} & a_{2,3}+c_{2,3} & a_{2,4}+b_{2,4} & a_{2,5}+b_{2,5} & a_{2,6}+b_{2,6} & 0 & 0 & 0 & 0 & 0 & 0 \\ a_{3,1}+c_{3,1} & a_{3,2}+c_{3,2} & a_{3,3}+c_{3,3} & a_{3,4}+b_{3,4} & a_{3,5}+b_{3,5} & a_{3,6}+b_{3,6} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & c_{4,4} & c_{4,5} & c_{4,6} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & c_{5,4} & c_{5,5} & c_{5,6} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & c_{6,4} & c_{6,5} & c_{6,6} & 0 & 0 & 0 & 0 & 0 & 0 \\ a_{4,4}+b_{1,1} & a_{4,5}+b_{1,2} & a_{4,6}+b_{1,3} & b_{1,1}+c_{1,1} & b_{1,2}+c_{1,2} & b_{1,3}+c_{1,3} & 0 & 0 & 0 & 0 & 0 & 0 \\ a_{5,4}+b_{2,1} & a_{5,5}+b_{2,2} & a_{5,6}+b_{2,3} & b_{2,1}+c_{2,1} & b_{2,2}+c_{2,2} & b_{2,3}+c_{2,3} & 0 & 0 & 0 & 0 & 0 & 0 \\ a_{6,4}+b_{3,1} & a_{6,5}+b_{3,2} & a_{6,6}+b_{3,3} & b_{3,1}+c_{3,1} & b_{3,2}+c_{3,2} & b_{3,3}+c_{3,3} & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & a_{4,1} & a_{4,2} & a_{4,3} \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & a_{5,1} & a_{5,2} & a_{5,3} \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & a_{6,1} & a_{6,2} & a_{6,3} \\ \end{array} \right)$

Note: I renamed A, B, C to aa, bb, cc because you should avoid starting user Symbols with capital letters; for example C is as protected System` Symbol:

Set::wrsym: Symbol C is Protected. >>

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
1
A = Table[Subscript[a, i, j], {i, 6}, {j, 6}];
B = Table[Subscript[b, i, j], {i, 6}, {j, 6}];
Cc = Table[Subscript[c, i, j], {i, 6}, {j, 6}];

m0 = ConstantArray[0, {3, 3}];

M = ArrayFlatten[{

   {A[[;; 3, ;; 3]] + Cc[[;; 3, ;; 3]]   ,A[[;; 3, 4 ;; 6]] + B[[;; 3, 4 ;; 6]], m0, m0},
   {m0                                   , Cc[[4 ;; 6, 4 ;; 6]]                , m0, m0},
   {A[[4 ;; 6, 4 ;; 6]] + B[[;; 3, ;; 3]],B[[;; 3, ;; 3]] + Cc[[;; 3, ;; 3]]   , m0, m0},
   {m0                                   , m0                                  , m0, A[[4 ;; 6, ;; 3]]}

        }];

Or, equivalently :

enter image description here

andre314
  • 18,474
  • 1
  • 36
  • 69