Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

Partition of a given matrix into block matrix form

asked 7 years ago

Deepak Sarma gravatar image

Q: Suppose B= block_matrix([ [P, Q], [R, S] ]) be a given matrix. Now if I type B[0,0], sage gives me the very first element of the matrix P, but I actually need the matrix P. How to get this one?

My actual problem is as follows.

Q: I have a 12X12 matrix A, I want to partition it into 3X3 block matrix. Then I need another 12x12 matrix (partitioned into 3x3 block) where (i,j)th block is the sum of (i,j)th block and (j,i)th block of the given matrix A.

Any suggestion will be highly appreciated. Thank you in advanced.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
0

answered 7 years ago

tmonteil gravatar image

You could try:

sage: B.subdivision(0,0)
Preview: (hide)
link

Comments

Thank you.

Deepak Sarma gravatar imageDeepak Sarma ( 7 years ago )
0

answered 7 years ago

B r u n o gravatar image

You can access the (i,j)-th block using B.subdivision(i,j).

For your more general problem:

sage: A = random_matrix(ZZ,12,12)
sage: A.subdivide([3,6,9],[3,6,9])
sage: B = block_matrix([[A.subdivision(i,j) + A.subdivision(j,i) for i in range(4)] for j in range(4)])
sage: A

[   0   -1    1|   1    0    1| -18   -1   -2|  -1    1   -1]
[  -1    8 -312|  16    1   -3|   3    0    0|   0   -1    0]
[   0  -13   -1|   4    2   -1|  -1    1    1|  21   -6    1]
[--------------+--------------+--------------+--------------]
[   1   -3   -4|   2   -2    2|  -3    2    0|  -1    3    0]
[  -1    1    1|  -2   -1   -2|  -1   -3   -1|   0   -1    6]
[   5    1    1|  -1   -1   -2|  -7   -1    0|   1   -1    1]
[--------------+--------------+--------------+--------------]
[  -1    4   -3|   1    4  -15|   5    1    1|   1    0    2]
[   5    0    0|   2   -1   -1| -16   -2    1|   0   -2   -1]
[   0    1    0|  -2    1    5|   8  -11    1|  -7   -1   -2]
[--------------+--------------+--------------+--------------]
[   1    1   -4|  -6   -1    3|-217   -1    0|   3    0   -1]
[  -1    0    1|   0   -7    0|  -1    3    1|  -3    3    1]
[  -1    0    0|   2    0   -1|  -2   -2    0|  -1   -2    0]
sage: B

[   0   -2    2|   2   -3   -3| -19    3   -5|   0    2   -5]
[  -2   16 -624|  15    2   -2|   8    0    0|  -1   -1    1]
[   0  -26   -2|   9    3    0|  -1    2    1|  20   -6    1]
[--------------+--------------+--------------+--------------]
[   2   -3   -3|   4   -4    4|  -2    6  -15|  -7    2    3]
[  15    2   -2|  -4   -2   -4|   1   -4   -2|   0   -8    6]
[   9    3    0|  -2   -2   -4|  -9    0    5|   3   -1    0]
[--------------+--------------+--------------+--------------]
[ -19    3   -5|  -2    6  -15|  10    2    2|-216   -1    2]
[   8    0    0|   1   -4   -2| -32   -4    2|  -1    1    0]
[  -1    2    1|  -9    0    5|  16  -22    2|  -9   -3   -2]
[--------------+--------------+--------------+--------------]
[   0    2   -5|  -7    2    3|-216   -1    2|   6    0   -2]
[  -1   -1    1|   0   -8    6|  -1    1    0|  -6    6    2]
[  20   -6    1|   3   -1    0|  -9   -3   -2|  -2   -4    0]
Preview: (hide)
link

Comments

Thank you very much.

Deepak Sarma gravatar imageDeepak Sarma ( 7 years ago )

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 7 years ago

Seen: 620 times

Last updated: Nov 15 '17