Ask Your Question
1

Is it possible to join matrices in to a bigger matrix?

asked 2012-05-01 18:58:57 +0100

Shashank gravatar image

I have two symbolic $2 \times 2$ matrices $A$ and $B$. I want to join them into a $4 \times 4$ matrix of the form $\begin{pmatrix}A & B \cr B & A\end{pmatrix}$.

The problem is that when I give

C=matrix(SR,4,4)
C=matrix([[A,B],[B,A]])

I get a three dimensional object, not a four by four matrix. The actual matrices I am working with are bigger than this, so I don't want to do it by hand. Is there a way of doing this without a bunch of for loops?

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
3

answered 2012-05-02 04:42:57 +0100

Jason Grout gravatar image

updated 2012-05-02 04:43:54 +0100

Use the block_matrix command instead of the matrix command:

var('x,y')
A=matrix([[x,y],[x^2,y^2]])
B=matrix([[2*x,3*y],[4*x,5*y]])
C=block_matrix(SR,[[A,B],[B,A]])
C

http://aleph.sagemath.org/?q=789a5a21...

edit flag offensive delete link more
1

answered 2012-05-01 19:27:03 +0100

ndomes gravatar image
M = matrix(4,4,0)
A = matrix(2,2,[1,2,3,4])
M.set_block(0,0,A)
M
edit flag offensive delete link more
1

answered 2012-05-01 19:44:07 +0100

achrzesz gravatar image

For example:

A=matrix(2,2,range(1,5))
B=A*10
AA=A.block_sum(A)
AA.set_block(0,2,B)
AA.set_block(2,0,B)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2012-05-01 18:58:57 +0100

Seen: 6,172 times

Last updated: May 02 '12