First time here? Check out the FAQ!

Ask Your Question
1

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

asked 12 years ago

Shashank gravatar image

I have two symbolic 2×2 matrices A and B. I want to join them into a 4×4 matrix of the form (ABBA).

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?

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
3

answered 12 years ago

Jason Grout gravatar image

updated 12 years ago

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

Preview: (hide)
link
1

answered 12 years ago

ndomes gravatar image
M = matrix(4,4,0)
A = matrix(2,2,[1,2,3,4])
M.set_block(0,0,A)
M
Preview: (hide)
link
1

answered 12 years ago

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)
Preview: (hide)
link

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: 12 years ago

Seen: 6,429 times

Last updated: May 02 '12