Ask Your Question
0

Partition of a given matrix into block matrix form

asked 2017-11-15 01:09:16 -0600

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.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-11-15 03:01:17 -0600

tmonteil gravatar image

You could try:

sage: B.subdivision(0,0)
edit flag offensive delete link more

Comments

Thank you.

Deepak Sarma gravatar imageDeepak Sarma ( 2017-11-15 06:59:08 -0600 )edit
0

answered 2017-11-15 02:58:37 -0600

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]
edit flag offensive delete link more

Comments

Thank you very much.

Deepak Sarma gravatar imageDeepak Sarma ( 2017-11-15 06:59:25 -0600 )edit

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: 2017-11-15 01:09:16 -0600

Seen: 29 times

Last updated: Nov 15