Post Reply 
Assigning a submatrix to an existing matrix
12-20-2023, 04:22 PM
Post: #3
RE: Assigning a submatrix to an existing matrix
(12-19-2023 02:37 PM)komame Wrote:  
(12-19-2023 10:17 AM)deSitter Wrote:  How do I say put a 2x2 matrix into an existing 4x4 matrix? Say I want to overwrite the elements in rows 1,2 and columns 3,4 with a 2x2 matrix - can I do this by direct assignment? Thanks in advance.

4x4 matrix:
mt1:=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]

2x2 matrix:
mt2:=[[−1,−2],[−3,−4]]

REPLACE(mt1,{1,3},mt2)

and you will get:
Code:
[[ 1, 2,−1,−2],
 [ 5, 6,−3,−4],
 [ 9,10,11,12],
 [13,14,15,16]]

Piotr

Thanks, close enough Smile

-drl
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Assigning a submatrix to an existing matrix - deSitter - 12-20-2023 04:22 PM



User(s) browsing this thread: 1 Guest(s)