# Splitting a matrix Anonymous

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

Sort by » oldest newest most voted

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]
)

more