Ask Your Question

# Is it possible to join matrices in to a bigger matrix? 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 close merge delete

## 3 Answers

Sort by » oldest newest most voted

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...

more M = matrix(4,4,0)
A = matrix(2,2,[1,2,3,4])
M.set_block(0,0,A)
M

more

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)

more

## Your Answer

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

Add Answer

## Stats

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

Seen: 3,569 times

Last updated: May 02 '12