# Creating a matrix from block

Anonymous

Suppose I have the following elements

A=matrix([[1, 2, 3, 4],[4, 3, 2, 1],[2, 4, 3, 1]])
b=vector([10, 20, 30])
c=vector([1, -2, 3, -1])
II=identity_matrix(3)
z=zero_vector(4)


Now I would like to construct a block matrix

A I | b

c z | 0

0 being a scalar

the | being facultative. I have tried many combination with block_matrix but with any success

edit retag close merge delete

Sort by » oldest newest most voted

I'm not sure what you've tried, but you need to convert the vectors to matrices:

sage: A = matrix([[1, 2, 3, 4],[4, 3, 2, 1],[2, 4, 3, 1]])
sage: II = identity_matrix(3)
sage: b = vector([10, 20, 30])
sage: c = vector([1, -2, 3, -1])
sage: z = zero_vector(3) # use a vector with 3 entries, for consistency with the size of II

sage: m = block_matrix(2, [[A, II, matrix(b).transpose()], [matrix(c), matrix(z), zero_matrix(1, 1)]])
sage: m
[ 1  2  3  4| 1  0  0|10]
[ 4  3  2  1| 0  1  0|20]
[ 2  4  3  1| 0  0  1|30]
[-----------+--------+--]
[ 1 -2  3 -1| 0  0  0| 0]


Now you can modify the subdivisions, if you don't like the current ones. For example:

sage: m.subdivisions()  # current subdivision
([3], [4, 7])
sage: m.subdivide([3], [7])
sage: m
[ 1  2  3  4  1  0  0|10]
[ 4  3  2  1  0  1  0|20]
[ 2  4  3  1  0  0  1|30]
[--------------------+--]
[ 1 -2  3 -1  0  0  0| 0]

more

Thanks John

( 2020-07-31 06:34:24 +0200 )edit