Ask Your Question
1

Convert a matrix to a list of equations

asked 2018-08-29 14:24:30 -0600

matrixman gravatar image

Hi there, I have a matrix A with entries depending linearly on a number of parameters a1,...,an, and would like to solve the equation A=0. It seems I need to convert A to a list of equations of the form "entry=0" and then use solve(eqns, a1,...,an); but how do I convert A to such a list?

Any help appreciated!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-08-29 15:41:04 -0600

tmonteil gravatar image

Given a matrix M, say:

sage: M = matrix(ZZ, [[4, 27, -3], [-3, 2, -1], [-177, 45, 5]])
sage: M
[   4   27   -3]
[  -3    2   -1]
[-177   45    5]

You can get its entries by doing:

sage: M.coefficients()
[4, 27, -3, -3, 2, -1, -177, 45, 5]
edit flag offensive delete link more

Comments

Thanks tmonteil, that's good to know! Is there also a way to convert the list of coefficients to a list of equations, setting each coefficient == 0?

matrixman gravatar imagematrixman ( 2018-08-29 16:33:47 -0600 )edit

yes, like this:

[c == 0 for c in M.coefficients()]
eric_g gravatar imageeric_g ( 2018-08-30 06:29:33 -0600 )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

Stats

Asked: 2018-08-29 14:24:30 -0600

Seen: 38 times

Last updated: Aug 29