10

How do I turn a system of sympy equations into a matrix form?

For example, how do I turn a system like this:

equation_one = 4*a*x + 3*b*y
equation_two = 2*b*x + 1*a*y

Into a system like this:

matrix_form = ([equation_one, equation_two], [x, y])

That will return this:

[[4*a, 3*b], 
 [2*b, 1*a]]

Does a function like matrix_form() exist?

Paul Terwilliger
  • 1,596
  • 1
  • 20
  • 45

1 Answers1

16

After some searching, I found

sympy.linear_eq_to_matrix(equations, *symbols)

This has solved my problem.

Paul Terwilliger
  • 1,596
  • 1
  • 20
  • 45