Ask Your Question
0

Creating a matrix from block

asked 2020-07-30 23:08:50 +0100

anonymous user

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-07-30 23:58:30 +0100

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

Comments

Thanks John

Cyrille gravatar imageCyrille ( 2020-07-31 06:34:24 +0100 )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: 2020-07-30 23:08:50 +0100

Seen: 739 times

Last updated: Jul 30 '20