# Help with building matrices

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

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

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}];

• Useful functions here: Plus, Span, ArrayFlatten, ConstantArray. – Sjoerd C. de Vries Dec 15 '14 at 18:47
• Avoid using subscripts until you become an expert – Dr. belisarius Dec 15 '14 at 19:04
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Dec 15 '14 at 19:05

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_{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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. >>

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 :