Ask Your Question
0

Splitting a matrix

asked 2021-03-25 20:18:08 +0100

anonymous user

Anonymous

updated 2021-03-25 20:20:03 +0100

Dear SAGE community, I am looking for a way that can help me split this matrix, A A = matrix([[x], [x - 2*y]]), which is a linear combination of variables x, and y

into a Coefficient matrix, C = matrix([[1, 0], [1, -2]]) times the vector containing independent variables b = matrix([[x], [y]]). Basically, A = C*b.

If there's a way to obtain the matrix C, would be really helpful.

-TIA

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-03-25 23:51:14 +0100

slelievre gravatar image

Since you know that the variables are x and y, grab their coefficients in each entry of A.

Use list comprehension to build a list of lists out of that.

Then create a matrix from this list of list.

The variables:

sage: x, y = SR.var('x, y')

The matrix A:

sage: A = matrix([[x], [x - 2*y]])
sage: A
[      x]
[x - 2*y]

The vector of variables:

sage: b = matrix([[x], [y]])

The matrix of coefficients:

sage: C = matrix([[e.coefficient(x), e.coefficient(y)] for row in A for e in row])

Check:

sage: C, b, C*b, A
(
[ 1  0]  [x]  [      x]  [      x]
[ 1 -2], [y], [x - 2*y], [x - 2*y]
)
edit flag offensive delete link more

Comments

@slelievre, Thank you very much for suggesting!

Apoorv gravatar imageApoorv ( 2021-03-26 07:17:31 +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: 2021-03-25 20:18:08 +0100

Seen: 461 times

Last updated: Mar 25 '21