I have a two matrix mm and nn. Matrix mm is of dimension 8 cross 8 and nn is of dimensions 4 cross 4. I want to replace the first four rows and columns in mm by nn. How to do this?
mm = ConstantArray[q, {8, 8}]
nn = ConstantArray[r, {4, 4}]
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityyou can use Table
and make any changes you like
Table[mm[[j, k]] = nn[[j, k]], {j, 4}, {k, 4}]
{{r,r,r,r,q,q,q,q},{r,r,r,r,q,q,q,q},{r,r,r,r,q,q,q,q},{r,r,r,r,q,q,q,q},{q,q,q,q,q,q,q,q},{q,q,q,q,q,q,q,q},{q,q,q,q,q,q,q,q},{q,q,q,q,q,q,q,q}}
mm[[;; 4, ;; 4]] = nn
. $\endgroup$