Ask Your Question
1

Convert a matrix to a list of equations

asked 2018-08-29 21:24:30 +0200

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 22:41:04 +0200

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 23:33:47 +0200 )edit

yes, like this:

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

Seen: 1,014 times

Last updated: Aug 29 '18