# Special addition of a small matrix to a large matrix, which will increase its size

I have a matrix $2\times2$. My job is to evaluate it and then add it to a large parent matrix which later will be analyzed.
In steps, I have a $2\times2$ evaluated matrix(in my case I have to integrate it, then use it).
Before that, I have a large matrix, for present case you can say $7\times7$. I have to add this(i.e. $2\times2$) matrix at non diagonal places, but as it is a matrix not a number so it will increase the size of the parent large matrix.

For example:

MLarge:= Table[i KroneckerDelta[i,j], {i, 1, 7}, {j, 1, 7}]
Meval:= {{0,3},{3,0}}


MLarge := $\left( \begin{array}{ccccccc} 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 2 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 3 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 4 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 5 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 6 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 7\\ \end{array} \right)$, Meval := $\left( \begin{array}{cc} (0 & 3)\\ (3 & 0) \\ \end{array} \right)$

Just to show that it(Meval) will be added to the MLarge, inner barkets are merely to show or point there addition in the MLarge(to make it clear). As large brakets(outside of Meval) was not possible for me to show or add in the Mfinal(to clearly mention there addition).

So, the result should be like this,

Mfinal := $\left( \begin{array}{ccccccccccccc} 1 & (0 & 3) & (0 & 3) & (0 & 3) & (0 & 3)& (0 & 3) & (0 & 3) \\ 1 & (3 & 0) & (3 & 0) & (3 & 0) & (3 & 0) & (3 & 0) & (3 & 0) \\ (0 & 3) & 2 & 0 & 0 & 0 & 0 & 0 \\ (3 & 0) & 2 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 3 & 0 & 0 & 0 & 0 \\ 0 & 0 & 3 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 4 & 0 & 0 & 0 \\ 0 & 0 & 0 & 4 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 5 & 0 & 0 \\ 0 & 0 & 0 & 0 & 5 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 6 & 0 \\ 0 & 0 & 0 & 0 & 0 & 6 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 7\\ 0 & 0 & 0 & 0 & 0 & 0 & 7\\ \end{array} \right)$

I have not added all the pieces, as it is cumbersome and time consuming but I really hope it is clear, if not I will make it more clear. Where ever we have left $0$(non diagonal entries) it will be changed by a matrix Meval. So, $7\times7$ has become $14\times13$
But how can I achieve this? I have no idea. Any help will be highly appreciable.

We only want to make changes at respective positions(not all), like at $(i,j),$ and $(i,j+2),$ $(i+2,j)$. e.g below

When we want two different matrices(containing variables) at different locations, e.g.

Mdiag[x_,y_] := $\left( \begin{array}{cc} 0 & x\\ y & 0 \\ \end{array} \right)$, Mnondiag[j_,k_] := $\left( \begin{array}{cc} 0 & j\\ k & 0 \\ \end{array} \right)$

Mdiag to be added to the MLarge on the diagonals and Mnondiag at $(i,j+2)$ and $(i+2,j)$.

They should look like this:
Mfinal := $\left( \begin{array}{ccccccccccccc} 1+0 & x & 0 & 0 & (0 & j) & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ y & 0 & 0 & 0 & (k & 0) & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 2 & x & 0 & 0 & 0 & j & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & y & 0 & 0 & 0 & k & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 3 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 4 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 5 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 6 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 7\\ 0 & 0 & 0 & 0 & 0 & 0 & 0\\ \end{array} \right)$
(just first two(or four in the Mfinal) rows, indicating the case).

I still didn't have the complete answer or far from it, any help or push in that direction will be of great use to me.

Mfinal = ArrayFlatten[MLarge /. 0 -> Meval];

MatrixForm[Mfinal]


Dimensions @ Mfinal


{14, 14}

• Thanks a lot for the neat and simple solution. – Shamina Jan 16 '17 at 9:40
• Good one, can you also show some light on the addendum, it will of a great use to me. Thanks once again. – Shamina Jan 16 '17 at 9:45
• @Shamina, welcome to mma.se. I suggest you post the addendum as a new question. – kglr Jan 16 '17 at 16:24