# Special addition of a small matrices at particular position to a large matrix

This is second and important part of question(previous one), but I will make it self contained.

We have a matrix say MLarge and we want to add two matrices to it at special positions, described by the conditions.
We only want to make changes at respective positions(not all), like numbers at $(i,j),$ and $(i,j+2),$ $(i+2,j)$ in MLarge should be changed with matrix. e.g below

When we want to specially add two different matrices(containing variables) at different locations,
For example:

MLarge:= Table[i KroneckerDelta[i,j], {i, 1, 7}, {j, 1, 7}];


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)$,

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[x_,j_,y_,k_] := $\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)$

Here, just first two(or four in the Mfinal) rows, indicating the case, I am interested in.
A general formalism will be of great use, general means adding matrix or matrices(with variables as above) at any desired location.
Any help will be highly appreciable, as I am new I forgive for asking obvious questions.

• you mean $(i,i+2)$ and $(i+2, i)$ instead of $(i,j+2)$ and $(j+2, i)$? – kglr Jan 16 '17 at 19:59
• Yes, and you implemented it also. Thanks for your advice of posting it separately. – Shamina Jan 17 '17 at 8:52

ClearAll[insertF]