Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
0

Transforming a matrix into a system of equations

asked 8 years ago

anonymous user

Anonymous

I have a n×n matrix that I would like to transform into a system of n equations (for n disctinct variables). I am not sure how to proceed (the end goal being to solve the system eventually). The number of variables is not fixed. Should I consider every row of the lattice and map each coefficient cij to a string that I write as "c11x1+.....+c1n1xn+c1n. I am hoping there exists a more direct solution. Thanks!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 8 years ago

nbruin gravatar image

Something like:

sage: M=matrix(3,3,[1,2,3,4,5,6,7,8,9])
sage: P=PolynomialRing(QQ,M.nrows(),names="x")
sage: (vector(P.gen(i) for i in range(3))*M).list()
[x0 + 4*x1 + 7*x2, 2*x0 + 5*x1 + 8*x2, 3*x0 + 6*x1 + 9*x2]

perhaps? It will depend on your application a bit whether you need to convert to/from lists and what kind of polynomial ring you need. A good rule of thumb is avoiding going through strings. It will be much more robust if the system knows the meaning of the objects throughout.

Preview: (hide)
link

Comments

thank you ! I have two additional questions. It seems that your solution gives the column coefficient to a polynomial (and not the rows). Would it be possible to have the row coefficients? One way would be to simple transpose the matrix beforehand. I have tried using M.ncolumns() but it seems to generate an error. Also, is there anyway the last coefficient could be a constant variable (1) (in order to have ax+by+c for example) ?

Sasha-dpt gravatar imageSasha-dpt ( 8 years ago )

If you multiply on the other side: M*(vector(P.gen(i) for i in range(3))) sage considers the vector as a column rather than a row. The right length is M.ncols() in that case. You can build your vector any way you like. You can just append a "1": vector([P.gen(i) for i in range(2)] + [1])

nbruin gravatar imagenbruin ( 8 years ago )

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: 8 years ago

Seen: 572 times

Last updated: Apr 04 '17