HP Forums
Assigning a submatrix to an existing matrix - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Assigning a submatrix to an existing matrix (/thread-21012.html)



Assigning a submatrix to an existing matrix - deSitter - 12-19-2023 10:17 AM

Hello Prime numbers,

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.

Many more questions coming, hope this isn't spam.

While I'm here - is there an outer product function? e.g. if you have a 2x3 array and a 3x4 array you create a 2x3x3x4 4-d array from a pair of 2-d arrays. I am working on an iterative construction of all Clifford algebras. Simple example is outer product of 2 vectors U_i, V_j then

(U outer V)_ij = U_i V*_j

where * = complex conjugate. Thanks.

-drl


RE: Assigning a submatrix to an existing matrix - komame - 12-19-2023 02:37 PM

(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


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

(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


RE: Assigning a submatrix to an existing matrix - ftneek - 11-26-2024 08:13 AM

(12-19-2023 10:17 AM)deSitter Wrote:  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?

In CAS, you can also use .. notation.

a:=[[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]]
a[1 .. 2,3 .. 4]:=[[3,4],[5,6]]

Results in

Code:
[[1,1,3,4],
[1,1,5,6],
[1,1,1,1],
[1,1,1,1]]

being assigned to a.