Ask Your Question
0

Transforming a matrix into a system of equations

asked 2017-04-04 05:21:45 +0100

anonymous user

Anonymous

I have a $n \times 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 $c_{ij}$ to a string that I write as $"c_{11}x_1 + .....+ c_{1n-1}x_n + c_{1n}$. I am hoping there exists a more direct solution. Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-04-04 09:10:50 +0100

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.

edit flag offensive delete link more

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 ( 2017-04-04 10:58:58 +0100 )edit

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 ( 2017-04-04 17:43:02 +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: 2017-04-04 05:21:45 +0100

Seen: 504 times

Last updated: Apr 04 '17